Client credentials

How to execute the authorization flow and get your access token

Sales channel applications use the client_credentials grant type to get a "guest" access token.

Integration applications use the client_credentials grant type to get an access token for themselves.

By including a scope in the access token request, all the resources that you fetch are automatically filtered.

Getting an access token

To get an access token using the client_credentials grant type, send a POST request to the /oauth/token endpoint, passing the application credentials in the request body.

Request

POST https://yourdomain.commercelayer.io/oauth/token

Arguments

Body parameter

Type

Required

Description

grant_type

string

Required

client_credentials

client_id

string

Required

Your application client_id

client_secret

string

Optional

Your application client_secret

scope

string

Optional

Your access token scope (market, stock location)

Sales channel applications require a market in scope when requesting their access token to perform the permitted CRUD actions. On the other hand, they don't require the client_secret argument. That lets you use them safely client-side.

Examples

Sales channel

Request
Response
Request

The following request tries to get an access token for a sales channel application, using the client_credentials grant type and putting in scope the market identified by the number "1234":

curl -X POST \
https://yourdomain.commercelayer.io/oauth/token \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"grant_type": "client_credentials",
"client_id": "your-client-id",
"scope": "market:1234"
}'
Response

On success, the API responds with a 200 OK status code, returning the requested access token:

{
"access_token": "your-access-token",
"token_type": "bearer",
"expires_in": 7200,
"scope": "market:1234",
"created_at": 123456789
}

Integration

Request
Response
Request

The following request tries to get an access token for an integration application, using the client_credentials grant type:

curl -X POST \
https://yourdomain.commercelayer.io/oauth/token \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"grant_type": "client_credentials",
"client_id": "your-client-id",
"client_secret": "your-client-secret"
}'
Response

On success, the API responds with a 200 OK status code, returning the requested access token:

{
"access_token": "your-access-token",
"token_type": "bearer",
"expires_in": 7200,
"scope": "market:all",
"created_at": 123456789
}