# Make your first API call Learn the fundamentals of using the HTTP API 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: - [Obtained your access token](/api/getting-started/make-first-api-call.md#get-your-access-token). - [Made your first API call](/api/getting-started/make-first-api-call.md#make-your-first-api-call). ## 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](/api/general-concepts.md#project) | your [Project setup](/api/getting-started/initial-setup.md#set-up-your-project) | | `{clientID}` | client\_id | your [API Client](/api/getting-started/create-api-client.md) | | `{clientSecret}` | secret | your [API Client](/api/getting-started/create-api-client.md) | | `{region}` | your Region | [Hosts](/api/general-concepts.md#hosts) | | `${BEARER_TOKEN}` | access\_token | from your [access token](/api/getting-started/make-first-api-call.md#get-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. This involves making an HTTP POST request to the [Authorization URL](/api/authorization.md#authorization-url) with the **client credentials** of the API Client you [created before](/api/getting-started/create-api-client.md). No headers or payload are required for this request, but you must include the following parameters for the [client credentials flow](/api/authorization.md#client-credentials-flow): | Parameter name | Value | | --- | --- | | grant\_type | `client_credentials` | | scope | At least one of the [scopes](/api/scopes.md) you assigned to your API Client, for example: `manage_project:{projectKey}` | ```http POST https://{clientID}:{clientSecret}@auth.{region}.commercetools.com/oauth/token ?grant_type=client_credentials &scope={scope} ``` ```curl curl -X POST https://{clientID}:{clientSecret}@auth.{region}.commercetools.com/oauth/token?grant_type=client_credentials&scope={scope} ``` ```json { "access_token": "NIMrFiOkdGWJdEKTY5uUe16OyE5jIbE6", "token_type": "Bearer", "expires_in": 172800, "scope": "manage_project:{projectKey}" } ``` With the value in `access_token` you can start making calls to the APIs. The token expires in 48 hours (172800 seconds). ## Make your first API call Now that you have your access token, you can make your first API call to your Project. You can retrieve the Project settings by making an HTTP GET request to your host's [API URL](/api/general-concepts.md#hosts) followed by the `{projectKey}` of your [Project](/api/general-concepts.md#project). You must provide the `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](https://curl.haxx.se/), you can include the header using the `-H` parameter as follows: If you can't see the cURL example below, switch the toggle in the top right corner to `cURL` instead of `http`. ```http GET https://api.{region}.commercetools.com/{projectKey}/ Authorization: Bearer ${BEARER_TOKEN} ``` ```curl curl https://api.{region}.commercetools.com/{projectKey}/ -X GET -H "Authorization: Bearer ${BEARER_TOKEN}" ``` ## Process response The response contains information about your Project, including the `name`, `countries`, `currencies`, and `languages` that are configured for your [Project](/search.md?urn=ctp:api:type:Project): ```json { "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 } } } } ``` If you find it difficult to read the response, use a JSON processor like `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: ```bash | 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. If you have received an error response instead, check that you have replaced all the [placeholder values](/api/getting-started/make-first-api-call.md#placeholder-values) with the correct values from your Project and API Client. Also verify that your API Client has the correct [scopes](/api/scopes.md) assigned to it. ## 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. ## Related pages - [Area overview page with navigation](/api.md) - [Previous page: Create an API client](/api/getting-started/create-api-client.md) - [Next page: Manage resources](/api/getting-started/manage-resources.md) - [Search documentation and API specs](/search.md)