# Roles and permissions

Commerce Layer supports a granular access control system on a resource level. Each access token gets a specific set of permissions. The client and the [authorization flow](https://docs.commercelayer.io/core/authentication#authorization-flows) determine your permitted actions for each resource.

{% content-ref url="authentication" %}
[authentication](https://docs.commercelayer.io/core/authentication)
{% endcontent-ref %}

### Sales channel

[Sales channels](https://docs.commercelayer.io/core/api-credentials#sales-channel) support `client_credentials`, `password` and `refresh_token` [grant types](https://docs.commercelayer.io/core/authentication#authorization-grant-flows). Given their limited permissions, they can be safely used in client-side applications.

#### Client credentials

Sales channels that authenticate through `client_credentials` get the following permissions.

{% hint style="danger" %}
For security reasons **sales channels** can read resource lists only for a subset of resources (e.g. SKUs, prices, bundles, etc. — *Show+List* in the table below). Getting a list is not allowed for all the other resources (only *Show* in the table below). For example, a sales channel is authorized to perform a `GET` request to the `/api/orders/xYZkjABcde` but not to the `/api/orders` endpoint.
{% endhint %}

<table><thead><tr><th width="160">Resource</th><th width="85" data-type="checkbox">Create</th><th width="90">Read<select multiple><option value="a3MVF89WVveV" label="Show" color="blue"></option><option value="MDJUWTMhGhy2" label="List" color="blue"></option></select></th><th width="90" data-type="checkbox">Update</th><th width="90" data-type="checkbox">Delete</th><th>Restrictions</th></tr></thead><tbody><tr><td><strong>Addresses</strong></td><td>true</td><td><span data-option="a3MVF89WVveV">Show</span></td><td>true</td><td>true</td><td>Single resource only.</td></tr><tr><td><strong>Application</strong></td><td>false</td><td><span data-option="a3MVF89WVveV">Show</span></td><td>false</td><td>false</td><td>The kind of <a href="api-credentials">API credentials</a> you're currently using.</td></tr><tr><td><strong>Bundles</strong></td><td>false</td><td><span data-option="MDJUWTMhGhy2">List, </span><span data-option="a3MVF89WVveV">Show</span></td><td>false</td><td>false</td><td>Bundles associated with the market in scope, or (if no market is in scope) with the currency code of the price list in scope.</td></tr><tr><td><strong>Customers</strong></td><td>true</td><td></td><td>false</td><td>false</td><td></td></tr><tr><td><strong>Customer password resets</strong></td><td>false</td><td></td><td>true</td><td>false</td><td></td></tr><tr><td><strong>Customer subscriptions</strong></td><td>true</td><td><span data-option="a3MVF89WVveV">Show</span></td><td>true</td><td>true</td><td>Single resource only.</td></tr><tr><td><strong>Delivery lead times</strong></td><td>false</td><td><span data-option="MDJUWTMhGhy2">List, </span><span data-option="a3MVF89WVveV">Show</span></td><td>false</td><td>false</td><td>Delivery lead times associated with the shipping methods accessible by scope.</td></tr><tr><td><strong>Geocoders</strong></td><td>false</td><td><span data-option="a3MVF89WVveV">Show</span></td><td>false</td><td>false</td><td>Single resource only.</td></tr><tr><td><strong>Gift cards</strong></td><td>true</td><td><span data-option="a3MVF89WVveV">Show</span></td><td>true</td><td>true</td><td>If draft (single resource only).</td></tr><tr><td><strong>Gift card recipients</strong></td><td>true</td><td><span data-option="a3MVF89WVveV">Show</span></td><td>true</td><td>true</td><td>Single resource only.</td></tr><tr><td><strong>In-stock subscriptions</strong></td><td>true</td><td><span data-option="a3MVF89WVveV">Show</span></td><td>true</td><td>true</td><td>In-stock subscriptions associated with the market in scope (single resource only).</td></tr><tr><td><strong>Line items</strong></td><td>true</td><td><span data-option="a3MVF89WVveV">Show</span></td><td>true</td><td>true</td><td>Can be read if belonging to <em>draft</em>, <em>pending</em> or <em>placed</em> orders and updated/deleted if belonging to <em>draft</em> or <em>pending</em> orders (single resource only).</td></tr><tr><td><strong>Line item options</strong></td><td>true</td><td><span data-option="a3MVF89WVveV">Show</span></td><td>true</td><td>true</td><td>Can be read if belonging line items associated with <em>draft</em>, <em>pending</em> or <em>placed</em> orders and updated/deleted if belonging to line items associated with <em>draft</em> or <em>pending</em> orders (single resource only).</td></tr><tr><td><strong>Notifications</strong></td><td>false</td><td><span data-option="MDJUWTMhGhy2">List, </span><span data-option="a3MVF89WVveV">Show</span></td><td>false</td><td>false</td><td></td></tr><tr><td><strong>Orders</strong></td><td>true</td><td><span data-option="a3MVF89WVveV">Show</span></td><td>true</td><td>false</td><td>Can be read if <em>draft</em>, <em>pending</em> or <em>placed</em>, as long as marked as <code>guest</code>. Can be updated if <em>draft</em> or <em>pending</em> (single resource only).</td></tr><tr><td><strong>Organization</strong></td><td>false</td><td><span data-option="a3MVF89WVveV">Show</span></td><td>false</td><td>false</td><td>Your current organization.</td></tr><tr><td><strong>Payment methods</strong></td><td>false</td><td><span data-option="MDJUWTMhGhy2">List, </span><span data-option="a3MVF89WVveV">Show</span></td><td>false</td><td>false</td><td>Enabled payment methods associated with the market in scope, or (if no market is in scope) with the currency code of the price list in scope.</td></tr><tr><td><strong>Payment sources</strong></td><td>true</td><td><span data-option="a3MVF89WVveV">Show</span></td><td>true</td><td>true</td><td>Can be read if belonging to <em>draft</em>, <em>pending</em> or <em>placed</em> orders and updated/deleted if belonging to <em>draft</em> or <em>pending</em> orders (single resource only).</td></tr><tr><td><strong>Prices</strong></td><td>false</td><td><span data-option="MDJUWTMhGhy2">List, </span><span data-option="a3MVF89WVveV">Show</span></td><td>false</td><td>false</td><td>Prices associated with the market price list.</td></tr><tr><td><strong>Price tiers</strong></td><td>false</td><td><span data-option="MDJUWTMhGhy2">List, </span><span data-option="a3MVF89WVveV">Show</span></td><td>false</td><td>false</td><td>Price tiers associated with the prices accessible by scope.</td></tr><tr><td><strong>Promotions</strong></td><td>false</td><td><span data-option="MDJUWTMhGhy2">List, </span><span data-option="a3MVF89WVveV">Show</span></td><td>false</td><td>false</td><td>Active promotions associated with the market in scope, or (if no market is in scope) with the currency code of the price list in scope, plus all promotions that aren't associated with any market and currency code.</td></tr><tr><td><strong>Promotion rules</strong></td><td>false</td><td><span data-option="a3MVF89WVveV">Show</span></td><td>false</td><td>false</td><td>Promotion rules associated with the promotions accessible by scope (single resource only).</td></tr><tr><td><strong>Reserved stocks</strong></td><td>false</td><td><span data-option="MDJUWTMhGhy2">List, </span><span data-option="a3MVF89WVveV">Show</span></td><td>false</td><td>false</td><td>Reserved stocks  belonging to the stock items of the stock locations associated with the market in scope.</td></tr><tr><td><strong>Shipments</strong></td><td>false</td><td><span data-option="a3MVF89WVveV">Show</span></td><td>true</td><td>false</td><td>Can be read if belonging to <em>draft</em>, <em>pending</em> or <em>placed</em> orders and updated if belonging to <em>draft</em> or <em>pending</em> orders (single resource only).</td></tr><tr><td><strong>Stock line items</strong></td><td>false</td><td><span data-option="a3MVF89WVveV">Show</span></td><td>false</td><td>false</td><td>Can be read if belonging to shipments associated with <em>draft</em>, <em>pending</em>, <em>editing</em> or <em>placed</em> orders (single resource only).</td></tr><tr><td><strong>Shipping methods</strong></td><td>false</td><td><span data-option="MDJUWTMhGhy2">List, </span><span data-option="a3MVF89WVveV">Show</span></td><td>false</td><td>false</td><td>Enabled shipping methods associated with the market in scope, or (if no market is in scope) with the currency code of the price list in scope. If stock location is specified, it's matched with the one in scope.</td></tr><tr><td><strong>Shipping method tiers</strong></td><td>false</td><td><span data-option="MDJUWTMhGhy2">List, </span><span data-option="a3MVF89WVveV">Show</span></td><td>false</td><td>false</td><td>Shipping method tiers associated with the shipping methods accessible by scope.</td></tr><tr><td><strong>SKUs</strong></td><td>false</td><td><span data-option="MDJUWTMhGhy2">List, </span><span data-option="a3MVF89WVveV">Show</span></td><td>false</td><td>false</td><td>SKUs with stock items in the market inventory model (unless not tracked), a price in the market price list (unless external prices allowed).</td></tr><tr><td><strong>SKU options</strong></td><td>false</td><td><span data-option="MDJUWTMhGhy2">List, </span><span data-option="a3MVF89WVveV">Show</span></td><td>false</td><td>false</td><td>SKU options associated with the market in scope, or (if no market is in scope) with the currency code of the price list in scope.</td></tr><tr><td><strong>SKU lists</strong></td><td>false</td><td><span data-option="a3MVF89WVveV">Show</span></td><td>false</td><td>false</td><td>Single resource only.</td></tr><tr><td><strong>SKU list items</strong></td><td>false</td><td><span data-option="a3MVF89WVveV">Show</span></td><td>false</td><td>false</td><td>Single resource only.</td></tr><tr><td><strong>Stock items</strong></td><td>false</td><td><span data-option="MDJUWTMhGhy2">List, </span><span data-option="a3MVF89WVveV">Show</span></td><td>false</td><td>false</td><td>SKU items belonging to the stock locations associated with the market in scope.</td></tr><tr><td><strong>Stock transfers</strong></td><td>false</td><td><span data-option="a3MVF89WVveV">Show</span></td><td>false</td><td>false</td><td>Can be read if belonging to shipments associated with <em>draft</em>, <em>pending</em>, <em>editing</em> or <em>placed</em> orders (single resource only).</td></tr><tr><td><strong>Subscription models</strong></td><td>false</td><td><span data-option="MDJUWTMhGhy2">List, </span><span data-option="a3MVF89WVveV">Show</span></td><td>false</td><td>false</td><td><p>Subscription models associated with the</p><p>market in scope.</p></td></tr><tr><td><strong>Tags</strong></td><td>false</td><td><span data-option="a3MVF89WVveV">Show</span></td><td>false</td><td>false</td><td>Allowed for <a href="https://app.gitbook.com/s/RWJeylueWkzLadK710XZ/tags#sales-channel-abilities">specific resources </a>only.</td></tr></tbody></table>

#### Password

Sales channels can authenticate a customer through the `password` flow. The access tokens that they get include the sum of the [client credentials permissions](#client-credentials) plus the ones below.

<table><thead><tr><th width="160">Resource</th><th width="90" data-type="checkbox">Create</th><th width="90" data-type="checkbox">Read</th><th width="90" data-type="checkbox">Update</th><th width="90" data-type="checkbox">Delete</th><th>Restrictions</th></tr></thead><tbody><tr><td><strong>Customers</strong></td><td>false</td><td>true</td><td>true</td><td>true</td><td>The customer must be the authenticated resource owner.</td></tr><tr><td><strong>Customer addresses</strong></td><td>true</td><td>true</td><td>true</td><td>true</td><td>The customer must be the authenticated resource owner.</td></tr><tr><td><strong>Customer payment sources</strong></td><td>false</td><td>true</td><td>true</td><td>true</td><td>The customer must be the authenticated resource owner.</td></tr><tr><td><strong>Customer subscriptions</strong></td><td>true</td><td>true</td><td>true</td><td>true</td><td>The customer must be the authenticated resource owner.</td></tr><tr><td><strong>Line items</strong></td><td>true</td><td>true</td><td>true</td><td>true</td><td>The line items must belong to one of the customer's orders.</td></tr><tr><td><strong>Line item options</strong></td><td>true</td><td>true</td><td>true</td><td>true</td><td>The line item options must belong to one of the line items associated with one of the customer's orders.</td></tr><tr><td><strong>Orders</strong></td><td>true</td><td>true</td><td>true</td><td>true</td><td>Can be deleted only if in <code>editing</code> status. The customer must be the authenticated resource owner.</td></tr><tr><td><strong>Order subscriptions</strong></td><td>true</td><td>true</td><td>true</td><td>false</td><td>The subscriptions must be associated with one of the customer's orders.</td></tr><tr><td><strong>Order subscription items</strong></td><td>true</td><td>true</td><td>true</td><td>false</td><td>The subscriptions items must be associated with one of the customer's subscriptions.</td></tr><tr><td><strong>Parcels</strong></td><td>false</td><td>true</td><td>false</td><td>false</td><td>The parcels must belong to one of the customer's orders.</td></tr><tr><td><strong>Parcel line items</strong></td><td>false</td><td>true</td><td>false</td><td>false</td><td>The parcel line items must belong to one of the parcels associated with one of the customer's orders.</td></tr><tr><td><strong>Returns</strong></td><td>true</td><td>true</td><td>true</td><td>false</td><td>Can be created for one of the customer's order and updated if in <em>draft</em> status.</td></tr><tr><td><strong>Return line items</strong></td><td>true</td><td>true</td><td>false</td><td>false</td><td>The return line items must belong to one of the returns associated with one of customer's order.</td></tr><tr><td><strong>Shipments</strong></td><td>false</td><td>true</td><td>true</td><td>false</td><td>The shipments must belong to one of the customer's orders.</td></tr><tr><td><strong>SKU lists</strong></td><td>true</td><td>true</td><td>true</td><td>true</td><td>The customer must be the authenticated resource owner.</td></tr><tr><td><strong>SKU list items</strong></td><td>true</td><td>true</td><td>true</td><td>true</td><td>The customer must be the authenticated owner of the associated SKU list.</td></tr></tbody></table>

{% hint style="warning" %}
Since customer tokens extend sales channels abilities, to get a list of resources belonging to a customer for those resources that [sales channels](#sales-channel) cannot list you need to fetch them [as relationships](https://docs.commercelayer.io/core/fetching-relationships#fetching-a-list-of-related-resources-1-n-relationship) via the `api/customers` endpoint. For example, you can get all the orders belonging to a customer by querying with a customer token the endpoint `api/customers/xYZkjABcde/orders`, where `xYZkjABcde` is the ID of the customer for which the token was issued.
{% endhint %}

#### Refresh token

An access token obtained through a `refresh_token` inherit the same set of permissions as the one that expired.

### Integration

[Integrations](https://docs.commercelayer.io/core/api-credentials#integration) support the `client_credentials` grant type. The access tokens that they get include the set of permissions of their role.

{% hint style="info" %}
With very few exceptions, the [Core resources](https://app.gitbook.com/o/-Lfu_B3DKew-kvoEWzTk/s/RWJeylueWkzLadK710XZ/) not listed in one of the tables above are likely manageable using **integration** API credentials only.
{% endhint %}

### Webapp

[Webapps](https://docs.commercelayer.io/core/api-credentials#webapp) support `authorization_code` and `refresh_token` grant types. They don't bring any grants to the access tokens and get the set of permissions of the authenticated user's role. Access tokens obtained through a `refresh_token` inherit the same set of permissions as the one that expired.
