API credentials
An overview of Commerce Layer's API credentials types and how generate them
To use Commerce Layer API you need to be authorized in the first place. This means you need to get a valid access token. The permissions you're granted authenticating with that token are determined by the type of API client you used to get it. Three different types are currently available in order to get your credentials: sales channel, integration, and webapp. Which one to use depends on your specific use case.
You can fetch the information about your current API credentials (i.e. the one you used to get your access token) by querying the application endpoint of the Core API. You can manage all the CRUD action on all your API credentials using the Provisioning API. API credentials management is also available via the admin Dashboard — read this to learn how to do it.
Sales channel
Sales channels are used to build any customer touchpoint (e.g. your storefront with a fully-functional shopping cart and checkout flow).
Sales channels grant non-confidential (public) API credentials. They can authenticate by providing just a client ID and their permissions are restricted so that they can be safely used client-side and their tokens exposed to the public without any risks. For example, they can access only one order at a time (the one associated with the shopping cart you're about to checkout, identified by a not guessable, unique hashID) and respond with a 401 Unauthorized
error if you try to request a list of orders.
Sales channels require a market in scope when requesting their access tokens. This way all the API call results are automatically filtered based on the specified scope. In particular:
Only the SKUs that are sellable in that market are returned (to be sellable in a market an SKU must have a price in the market's price list and at least one stock item in one of the market's stock locations, regardless of its quantity).
Only the prices associated with that market's price list are returned.
The stock availability is calculated by checking only the stock locations associated with that market (e.g. only the stock items associated with that market's stock locations are returned).
Using a sales channel is the most straightforward way to build your customer touchpoint. Anyway, if you want to have complete control over the grants brought to the access tokens, you can always use an integration. Just make sure not to expose the secret on the client, by building a dedicated backend for frontend (BFF), or properly leveraging serverless functions.
Integration
Integrations are used to develop backend integrations with any 3rd-party system.
Integrations provide confidential API credentials. They need a client ID and a client secret to authenticate and can have one of two roles:
Read-only — to perform
GET
requests on any single resource or list of resources.Admin — to perform any CRUD (create, retrieve, update, or delete) action on any resource.
Enterprise users can define custom roles for their integration API credentials, specifying custom permissions on CRUD actions at the single resource level so as to leverage a granular control, tailored to their needs.
Webapp
Webapps are used to develop custom web apps or services for your users, extending Commerce Layer backend with any functionality that is not provided out of the box.
Webapps let you execute the OAuth 2.0 authorization code grant flow to get an access token after a user authorizes an app. They don't come with their own roles and permissions, since they get the set of permissions of the authenticated user.
Generating API credentials
The Core API application endpoint is read-only, meaning that by using the API you can only retrieve the information about the API credentials within the current scope. The full set of CRUD operations (create, update, and delete) on all your API credentials are available via the Provisioning API or via the admin Dashboard, as shown in the screenshots below.
Head over to the API credentials section by clicking on the related item in the nav menu sidebar on the left of your dashboard. The list of your current available API credentials will be displayed. You can access each one individually to update or delete them. To create a new one, click on + New on the top right of the list:
![](https://docs.commercelayer.io/~gitbook/image?url=https%3A%2F%2F1360111082-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252F-LgByaSP8eKjad-MIuHE%252Fuploads%252FiXe34Ihl8WGz4qp1HWz3%252FAPI-credentials-list.jpg%3Falt%3Dmedia%26token%3Db317ed80-5594-4b0d-9b25-2d9c1e197843&width=768&dpr=4&quality=100&sign=84aad200&sv=1)
The following page is where you can select the kind of API credentials you want to create.
Sales channel
To create a sales channel, select the Sales channel card, give your new API credentials a meaningful name, and click on the Create button:
![](https://docs.commercelayer.io/~gitbook/image?url=https%3A%2F%2F1360111082-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252F-LgByaSP8eKjad-MIuHE%252Fuploads%252F1Bf4dduZRuunVCgZMJmJ%252Fselect-sales-channel.jpg%3Falt%3Dmedia%26token%3Dc342b3e8-e50c-4151-90ff-b46506ed7001&width=768&dpr=4&quality=100&sign=9f96341&sv=1)
![](https://docs.commercelayer.io/~gitbook/image?url=https%3A%2F%2F1360111082-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252F-LgByaSP8eKjad-MIuHE%252Fuploads%252F3h9aMLHH0ZpZF5Z7hEoh%252Fnew-sales-channel.jpg%3Falt%3Dmedia%26token%3Dc677693a-b9e2-41e6-b48e-0120368d1922&width=768&dpr=4&quality=100&sign=9826bda9&sv=1)
On successful creation, you will enter the details page, where you can find and copy to clipboard your API credentials (client ID, base endpoint, and allowed scopes):
![](https://docs.commercelayer.io/~gitbook/image?url=https%3A%2F%2F1360111082-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252F-LgByaSP8eKjad-MIuHE%252Fuploads%252FOYi8CM4wFAk7oi9MkQE5%252Fsales-channel-credentials.jpg%3Falt%3Dmedia%26token%3D67cc796d-2846-43ac-a26f-c519caa1758b&width=768&dpr=4&quality=100&sign=aef876a4&sv=1)
To update or delete your sales channel just click on the three dots ...
button at the top right corner and select the desired action from the dropdown.
Integration
To create an integration, select the Integration card, give your new API credentials a meaningful name, choose its role from the related dropdown, and click on the Create button:
![](https://docs.commercelayer.io/~gitbook/image?url=https%3A%2F%2F1360111082-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252F-LgByaSP8eKjad-MIuHE%252Fuploads%252FXyNOqJbdpIEunoZRDVvv%252Fselect-integration.jpg%3Falt%3Dmedia%26token%3Db8d86ea6-0a41-4836-b9e4-f72a045ac161&width=768&dpr=4&quality=100&sign=1641f8b&sv=1)
![](https://docs.commercelayer.io/~gitbook/image?url=https%3A%2F%2F1360111082-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252F-LgByaSP8eKjad-MIuHE%252Fuploads%252Fv1mG1NE0Zjd1pKW5aaZM%252Fnew-integration.jpg%3Falt%3Dmedia%26token%3D8a7fa01b-b7be-4a07-9730-04560ad6c05a&width=768&dpr=4&quality=100&sign=ac14684&sv=1)
On successful creation, you will enter the details page, where you can find and copy to clipboard your API credentials (client ID, client secret, and base endpoint):
![](https://docs.commercelayer.io/~gitbook/image?url=https%3A%2F%2F1360111082-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252F-LgByaSP8eKjad-MIuHE%252Fuploads%252FwPgwH4bqgTmONqiCfOdz%252Fintegration-credentials.jpg%3Falt%3Dmedia%26token%3D6e10da12-c8a8-4b28-96bd-d2c0b7b703a5&width=768&dpr=4&quality=100&sign=9b330d1e&sv=1)
To update or delete your integration just click on the three dots ...
button at the top right corner and select the desired action from the dropdown.
Webapp
To create a webapp, select the Webapp card, give your new API credentials a meaningful name, insert the redirect URI (necessary for the authorization code flow), and click on the Create button:
![](https://docs.commercelayer.io/~gitbook/image?url=https%3A%2F%2F1360111082-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252F-LgByaSP8eKjad-MIuHE%252Fuploads%252FCpzRoKZXJs1td9I8MlWy%252Fselect-webapp.jpg%3Falt%3Dmedia%26token%3D678cb828-fce3-45c5-8f94-3e34581a811b&width=768&dpr=4&quality=100&sign=faefe6a&sv=1)
![](https://docs.commercelayer.io/~gitbook/image?url=https%3A%2F%2F1360111082-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252F-LgByaSP8eKjad-MIuHE%252Fuploads%252FcnAEUb4ZUYIgkwdrZsZC%252Fnew-webapp.jpg%3Falt%3Dmedia%26token%3D6105ed66-0de7-4491-8892-52d6c693cb80&width=768&dpr=4&quality=100&sign=cc142c8&sv=1)
On successful creation, you will enter the details page, where you can find and copy to clipboard your API credentials (client ID, client secret, and base endpoint):
![](https://docs.commercelayer.io/~gitbook/image?url=https%3A%2F%2F1360111082-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252F-LgByaSP8eKjad-MIuHE%252Fuploads%252FwofJM2zopTrZx9d9ECvX%252Fwebapp-credentials.jpg%3Falt%3Dmedia%26token%3Dbc13d495-fe8c-4764-902b-2c17c64272d5&width=768&dpr=4&quality=100&sign=a9c8a884&sv=1)
To update or delete your webapp just click on the three dots ...
button at the top right corner and select the desired action from the dropdown.
Last updated