> ## Documentation Index
> Fetch the complete documentation index at: /docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Call Your API Using the Client Credentials Flow

> Learn how to call your API from a machine-to-machine (M2M) application using the Client Credentials Flow.

This tutorial will help you call your API from a machine-to-machine (M2M) application using the Client Credentials Flow. To learn how the flow works and why you should use it, read [Client Credentials Flow](/docs/docs/get-started/authentication-and-authorization-flow/client-credentials-flow).

Auth0 makes it easy for your application to implement the Client Credentials Flow. Following successful authentication, the application will have access to an access token (Access Token: Authorization credential, in the form of an opaque string or JWT, used to access an API.), which can be used to call your protected APIs. To learn more about access tokens, read [Access Tokens](/docs/docs/secure/tokens/access-tokens).

## Prerequisites

**Before beginning this tutorial:**

* [Register your API with Auth0](/docs/docs/get-started/auth0-overview/set-up-apis)

  * [Add appropriate API permissions](/docs/docs/get-started/apis/add-api-permissions)
* [Register the M2M Application with Auth0](/docs/docs/get-started/auth0-overview/create-applications/machine-to-machine-apps).

  * Select an **Application Type** of **Machine to Machine Applications**.
  * Choose your previously-registered API.
  * Authorize the M2M Application to call your API.

## Steps

1. [Request tokens](#request-tokens):
   From the authorized application, request an access token for your API.
2. [Call API](#call-api):
   Use the retrieved access token to call your API.

Optional: [Explore sample use cases](#sample-use-cases)

### Request tokens

To access your API, you must request an access token for it. To do so, you will need to `POST` to the [token URL](/docs/docs/api/authentication/client-credential-flow/get-token).

#### Example POST to token URL

##### Parameters

| Parameter Name | Description |
| - | - |
| `grant_type` | Set this to "client\_credentials". |
| `client_id` | Your application's Client ID. You can find this value on the [application's settings tab](https://manage.auth0.com/#/applications). |
| `client_secret` | Your application's Client Secret. You can find this value on the [application's settings tab](https://manage.auth0.com/#/applications). To learn more about available application authentication methods, read [Application Credentials](/docs/docs/secure/application-credentials). |
| `audience` | The audience for the token, which is your API. You can find this in the **Identifier** field on your [API's settings tab](https://manage.auth0.com/#/apis). |
| `organization` | Optional. The organization name or identifier you want the request to be associated with. To learn more, read [Machine-to-Machine Access for Organizations](/docs/docs/manage-users/organizations/organizations-for-m2m-applications). |

#### Response

If all goes well, you'll receive an `HTTP 200` response with a payload containing `access_token`, `token_type`, and `expires_in` values:

```json lines theme={null}
{
  "access_token":"eyJz93a...k4laUWw",
  "token_type":"Bearer",
  "expires_in":86400
}
```

> [!WARNING]
>
> Validate your tokens before saving them. To learn how, read [Validate ID Tokens](/docs/docs/secure/tokens/id-tokens/validate-id-tokens) and [Validate Access Tokens](/docs/docs/secure/tokens/access-tokens/validate-access-tokens).

### Call API

To call your API from the M2M application, the application must pass the retrieved access token as a Bearer token in the Authorization header of your HTTP request.

### Sample use cases

#### Customize tokens

You can use [Actions](/docs/docs/customize/actions) to deny access tokens based on custom logic and/or add claims to access tokens. Auth0 invokes Actions attached to the client credentials grant at runtime to execute your custom logic.

To learn more, read about the Actions [Machine to Machine Flow](/docs/docs/customize/actions/explore-triggers/credentials-exchange).

#### View sample application: server client + API

For a sample implementation, read the [Server Client + API](/docs/docs/get-started/architecture-scenarios/server-application-api) architecture scenario. This series of tutorials is accompanied by a [code sample that you can access in GitHub](https://github.com/auth0-samples/auth0-pnp-exampleco-timesheets).

Once your API receives a request with an access token, it will need to validate the token. To learn more, read [Validate Access Tokens](/docs/docs/secure/tokens/access-tokens/validate-access-tokens).

## Learn more

* [Machine to Machine Triggers](/docs/docs/customize/actions/explore-triggers/credentials-exchange)
* [OpenID Connect Protocol](/docs/docs/authenticate/protocols/openid-connect-protocol)
* [Tokens](/docs/docs/secure/tokens)
