API Clients
View, create, and delete API Clients
To interact with commercetools Composable Commerce APIs, use an API Client with dedicated scopes that allow read or write access to resources within your project.
You must create your first API Client in the Merchant Center. After that, you can create additional clients in the Merchant Center or through the API Clients API. You can use the API Clients endpoints only from an authorized API Client.
The API Clients API is especially useful for Infrastructure as Code (IaC) tooling and for frequently rotating your API secrets.
commercetools Composable Commerce APIs use OAuth 2.0 for authorization.
Once you create an API Client, you cannot change it. The secret is visible only in the response when creating the API Client.
This API allows you to configure the expiration times of OAuth tokens for your API Client. If you want to set expiration times different to the default values shown below, you need to use this API instead of the Merchant Center for creating your API Client.
| Token type | Default | Minimum | Maximum |
|---|---|---|---|
| access token | 48 hours | 1 hour | 7 days |
| refresh token | 200 days | 30 seconds | 1 year |
Due to the sensitive nature of this API, it can not be used with the manage_project:{projectKey} scope, but only with manage_api_clients:{projectKey}.
Representations
APIClient
idString | The OAuth2 |
nameString | Name of the APIClient. |
scopeString | Whitespace-separated list of OAuth scopes that can be used when obtaining an access token. |
secretString | Only shown once in the response of creating the APIClient.
This is the OAuth2 |
lastUsedAtDate | Date of the last day this APIClient was used to obtain an access token. |
deleteAt | If set, the Client will be deleted on (or shortly after) this point in time. |
accessTokenValiditySecondsInt | Expiration time in seconds for each access token obtained by the APIClient. Only present when set with the APIClientDraft. If not present the default value applies. Default:172800Minimum: 3 600Maximum: 604 800 |
refreshTokenValiditySecondsInt | Inactivity expiration time in seconds for each refresh token obtained by the APIClient. Only present when set with the APIClientDraft. If not present the default value applies. Default:17280000Minimum: 30Maximum: 31 536 000 |
createdAt | Date and time (UTC) the APIClient was initially created. |
APIClientDraft
nameString | Name of the APIClient. |
scopeString | Whitespace-separated list of OAuth scopes that can be used when obtaining an access token. |
deleteDaysAfterCreationInt | If set, the Client will be deleted after the specified amount of days. |
accessTokenValiditySecondsInt | Expiration time in seconds for each access token obtained by the APIClient. If not set the default value applies. Default:172800Minimum: 3 600Maximum: 604 800 |
refreshTokenValiditySecondsInt | Inactivity expiration time in seconds for each refresh token obtained by the APIClient. The expiration time for refresh tokens is restarted each time the token is used. If not set the default value applies. Default:17280000Minimum: 30Maximum: 31 536 000 |
ApiClientPagedQueryResponse
PagedQueryResult with results containing an array of APIClient.
limitInt | Number of results requested. Default:20Maximum: 500 |
offsetInt | Number of elements skipped. Default:0Maximum: 10 000 |
countInt | Actual number of results returned. |
totalInt | Total number of results matching the query.
This number is an estimation that is not strongly consistent.
This field is returned by default.
For improved performance, calculating this field can be deactivated by using the query parameter |
resultsArray of ApiClient | APIClients matching the query. |
Get API Client
view_api_clients:{projectKey}regionString | Region in which the Project is hosted. |
projectKeyString |
|
idString |
|
application/jsoncurl --get https://api.{region}.commercetools.com/{projectKey}/api-clients/{id} -i \--header "Authorization: Bearer ${BEARER_TOKEN}"
{"id": "api-client-id","name": "api-client-name","scope": "view_products:{projectKey}","createdAt": "2018-01-01T00:00:00.001Z","lastUsedAt": "2017-09-10","accessTokenValiditySeconds": 3600,"refreshTokenValiditySeconds": 31536000}
Query API Clients
view_api_clients:{projectKey}regionString | Region in which the Project is hosted. |
projectKeyString |
|
where | The parameter can be passed multiple times. |
sort | The parameter can be passed multiple times. |
expand | The parameter can be passed multiple times. |
limitInt | Number of results requested. Default: 20 |
offsetInt | Number of elements skipped. Default: 0 |
withTotalBoolean | Controls the calculation of the total number of query results. Set to Default: true |
var.<varName>String | Predicate parameter values. The parameter can be passed multiple times. |
application/jsoncurl --get https://api.{region}.commercetools.com/{projectKey}/api-clients -i \--header "Authorization: Bearer ${BEARER_TOKEN}"
{"limit": 20,"offset": 0,"count": 1,"total": 1,"results": [{"id": "api-client-id","name": "api-client-name","scope": "view_products:{projectKey}","createdAt": "2018-01-01T00:00:00.001Z","lastUsedAt": "2017-09-10","accessTokenValiditySeconds": 3600,"refreshTokenValiditySeconds": 31536000}]}
Check if API Client exists
Check if API Client exists by ID
Checks if an API Client exists for a given id. Returns a 200 OK status if the API Client exists or a 404 Not Found otherwise.
view_api_clients:{projectKey}regionString | Region in which the Project is hosted. |
projectKeyString |
|
idString |
|
curl --head https://api.{region}.commercetools.com/{projectKey}/api-clients/{id} -i \--header "Authorization: Bearer ${BEARER_TOKEN}"
Check if API Client exists by Query Predicate
Checks if an API Client exists for a given Query Predicate. Returns a 200 OK status if any API Clients match the Query Predicate or a 404 Not Found otherwise.
view_api_clients:{projectKey}regionString | Region in which the Project is hosted. |
projectKeyString |
|
where |
curl --head https://api.{region}.commercetools.com/{projectKey}/api-clients -i \--header "Authorization: Bearer ${BEARER_TOKEN}"
Create API Client
Scopes cannot be changed after an API Client is created.
manage_api_clients:{projectKey}regionString | Region in which the Project is hosted. |
projectKeyString |
|
expand | The parameter can be passed multiple times. |
application/jsonapplication/jsoncurl https://api.{region}.commercetools.com/{projectKey}/api-clients -i \--header "Authorization: Bearer ${BEARER_TOKEN}" \--header 'Content-Type: application/json' \--data-binary @- << DATA{"name" : "api-client-name","scope" : "view_products:{projectKey}","accessTokenValiditySeconds" : 3600,"refreshTokenValiditySeconds" : 31536000}DATA
{"secret": "secret-passphrase","id": "api-client-id","name": "api-client-name","scope": "view_products:{projectKey}","createdAt": "2018-01-01T00:00:00.001Z","accessTokenValiditySeconds": 3600,"refreshTokenValiditySeconds": 31536000}
Delete API Client
manage_api_clients:{projectKey}regionString | Region in which the Project is hosted. |
projectKeyString |
|
idString |
|
application/jsoncurl -X DELETE https://api.{region}.commercetools.com/{projectKey}/api-clients/{id} -i \--header "Authorization: Bearer ${BEARER_TOKEN}"
{"id": "api-client-id","name": "api-client-name","scope": "view_products:{projectKey}","createdAt": "2018-01-01T00:00:00.001Z","lastUsedAt": "2017-09-10","accessTokenValiditySeconds": 3600,"refreshTokenValiditySeconds": 31536000}