View, create, and delete API Clients
The API Clients API is especially useful for Infrastructure as Code (IaC) tooling and for frequently rotating your API secrets.
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 |
manage_project:{projectKey} scope, but only with manage_api_clients:{projectKey}.Representations
APIClient
idString | The OAuth2 client_id that can be used to obtain an access token. |
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 client_secret that can be used to obtain an access token. |
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: 3600Maximum: 604800 |
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: 31536000 |
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: 3600Maximum: 604800 |
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: 31536000 |
ApiClientPagedQueryResponse
limitInt | Number of results requested. Default: 20Minimum: 0Maximum: 500 |
offsetInt | Number of elements skipped. Default: 0Maximum: 10000 |
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 withTotal=false.
When the results are filtered with a Query Predicate, total is subject to a limit. |
resultsArray of ApiClient | APIClients matching the query. |
Get API Client
view_api_clients:{projectKey}regionString | Region in which the Project is hosted. |
projectKeyString | key of the Project. |
idString | id of the API Client. |
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 | key of the Project. |
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: 20Minimum: 0Maximum: 500 |
offsetInt | Number of elements skipped. Default: 0Maximum: 10000 |
withTotalBoolean | Controls the calculation of the total number of query results. Set to false to improve query performance when the total is not needed.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
id. Returns a 200 status if the API Client exists, or a 404 status otherwise.view_api_clients:{projectKey}regionString | Region in which the Project is hosted. |
projectKeyString | key of the Project. |
idString | id of the API Client. |
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
200 status if any API Clients match the query predicate, or a 404 status otherwise.view_api_clients:{projectKey}regionString | Region in which the Project is hosted. |
projectKeyString | key of the Project. |
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 | key of the Project. |
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 | key of the Project. |
idString | id of the API Client. |
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
}