The HTTP API is the core of commercetools Composable Commerce. Everything in your Project can be retrieved and modified using the HTTP API.
Objectives of this guide
The objective of this guide is to help you make your first API call to your Project. This is to make sure you have everything set up correctly and understand the basics of how to interact with the API.
Upon completing this guide, you will have:
Placeholder values
Since some parameters used in this guide are specific to your Project, the examples use the following placeholders that you should replace with the actual values from your Project and API Client.:
Placeholder | Replace with | From |
---|---|---|
{projectKey} | project_key | your API Client |
{clientID} | client_id | your API Client |
{clientSecret} | secret | your API Client |
{region} | your Region | Hosts |
${BEARER_TOKEN} | access_token | from your access token response |
Get your access token
Before you can access resources in your Project, you must first get a token from the OAuth 2.0 service and then provide it with every API call.
Parameter name | Value |
---|---|
grant_type | client_credentials |
scope | At least one of the scopes you assigned to your API Client, for example: manage_project:{projectKey} |
POST https://{clientID}:{clientSecret}@auth.{region}.commercetools.com/oauth/token
?grant_type=client_credentials
&scope={scope}
{
"access_token": "NIMrFiOkdGWJdEKTY5uUe16OyE5jIbE6",
"token_type": "Bearer",
"expires_in": 172800,
"scope": "manage_project:{projectKey}"
}
access_token
you can start making calls to the Composable Commerce API.The token expires in 48 hours (172800 seconds).
Make your first API call
{projectKey}
.Authorization
header with the access token you obtained in the previous step.
Replace the placeholder ${BEARER_TOKEN}
with your access_token
value, for example: Bearer NIMrFiOkdGWJdEKTY5uUe16OyE5jIbE6
.
If you are using cURL, you can include the header using the -H
parameter as follows:cURL
instead of http
.GET https://api.{region}.commercetools.com/{projectKey}/
Authorization: Bearer ${BEARER_TOKEN}
Process response
name
, countries
, currencies
, and languages
that are configured for your Project:{
"key": "{projectKey}",
"name": "{projectName}",
"countries": ["GB", "DE", "US"],
"currencies": ["EUR", "GBP", "USD"],
"languages": ["en-GB", "de-DE", "en-US"],
"createdAt": "2023-10-23T12:48:51.728Z",
"trialUntil": "2023-12",
"messages": {
"enabled": false,
"deleteDaysAfterCreation": 15
},
"carts": {
"deleteDaysAfterLastModification": 90,
"allowAddingUnpublishedProducts": false,
"countryTaxRateFallbackEnabled": false,
"cartDiscountCache": {
"enabled": false
},
"loadParsedDiscountsEnabled": false
},
"shoppingLists": {
"deleteDaysAfterLastModification": 360
},
"version": 9,
"searchIndexing": {
"products": {
"status": "Activated",
"lastModifiedAt": "2023-10-23T12:50:19.191Z",
"lastModifiedBy": {
"isPlatformClient": true
}
},
"orders": {
"status": "Activated",
"lastModifiedAt": "2023-10-23T12:49:11.387Z",
"lastModifiedBy": {
"isPlatformClient": true
}
}
}
}
jq
to format the output.
To filter out the information you are really interested in you can add the grep
command to the cURL request.
The example statement below will show you the Project name in the response only: | jq . | grep \"name\"
We chose the Project resource as example because it is available by default, even if your Project has no data. The objective is to provide a clear and simple way to get started with the API and understand the basic concepts. If you have succeeded in making this API call, you are now ready to manage other resources in your Project.
Next steps
Now that you have your access token and have made a successful API call to your Project, you are now ready to create, update, and query resources, such as Customers, Products, and Orders.