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

# Get Management API Access Tokens for Production

> Learn how to get Access Tokens to make scheduled frequent calls to the Management API.

To make scheduled frequent calls for a production environment, you have to build a process at your backend that will provide you with a token automatically (and thus simulate a non-expiring token).

## Prerequisites

* [Register Machine-to-Machine Applications](/docs/docs/get-started/auth0-overview/create-applications/machine-to-machine-apps).

## Get access tokens

To ask Auth0 for a Management API (Management API: A product to allow customers to perform administrative tasks.) v2 token, perform a `POST` operation to the `https://{yourDomain}/oauth/token` endpoint, using the credentials of the Machine-to-Machine Application you created in the prerequisite step.

The payload should be in the following format:

Remember to update `` `{yourClientSecret}` `` with the client secret (Client Secret: Secret used by a client (application) to authenticate with the Authorization Server; it should be known to only the client and the Authorization Server and must be sufficiently random to not be guessable.) in the [Settings tab of your Application](https://manage.auth0.com/#/applications/\{yourClientId}/settings).

The request parameters are:

| Request Parameter | Description |
| - | - |
| **grant\_type** | Denotes which [OAuth 2.0 flow](/docs/docs/authenticate/protocols/oauth#grant-types) you want to run. For machine to machine communication use the value `client_credentials`. |
| **client\_id** | This is the value of the **Client ID** field of the Machine-to-Machine Application you created. You can find it on the [Settings tab of your Application](https://manage.auth0.com/#/applications/\{yourClientId}/settings). |
| **client\_secret** | This is the value of the **Client Secret** field of the Machine-to-Machine Application you created. You can find it at the [Settings tab of your Application](https://manage.auth0.com/#/applications/\{yourClientId}/settings). |
| **audience** | This is the value of the **Identifier** field of the `Auth0 Management API`. You can find it at the [Settings tab of the API](https://manage.auth0.com/#/apis). |

> [!WARNING]
>
> Use the `update:client_grants` and `create:client_grants` scopes with only high-privileged applications, as they allow the client to grant further permissions to itself.

The response will contain a [signed JWT](/docs/docs/secure/tokens/json-web-tokens), an expiration time, the scopes granted, and the token type.

```json lines theme={null}
{
  "access_token": "eyJ...Ggg",
  "expires_in": 86400,
  "scope": "read:clients create:clients read:client_keys",
  "token_type": "Bearer"
}
```

From the above, we can see that our Access Token (Access Token: Authorization credential, in the form of an opaque string or JWT, used to access an API.) will expire in 24 hours (86400 seconds), it has been authorized to read and create applications, and it is a [Bearer Access Token](https://tools.ietf.org/html/rfc6750).

### Use Auth0's Node.js client library

As an alternative to making HTTP calls, you can use the [node-auth0](https://www.npmjs.com/package/auth0) library to automatically [obtain tokens for the Management API](https://www.npmjs.com/package/auth0#user-content-management-api-client).

## Use access tokens

To use this token, include it in the `Authorization` header of your request.

For example, in order to [Get all applications](/docs/docs/api/management/v2/clients/get-clients) use the following:

Using the Auth0 CLI? If you haven't already, [set up and authenticate your CLI session](/docs/docs/deploy-monitor/auth0-cli) before running this command.

You can get the curl command for each endpoint from the Management API v2 Explorer. Go to the endpoint you want to call, and click the **get curl command** link at the **Test this endpoint** section.

## Example: Python implementation

This python script gets a Management API v2 Access Token, uses it to call the [Get all applications](/docs/docs/api/management/v2/clients/get-clients) endpoint, and prints the response in the console.

Before you run it make sure that the following variables hold valid values:

* `AUDIENCE`: The **Identifier** of the `Auth0 Management API`. You can find it at the [Settings tab of the API](https://manage.auth0.com/#/apis).
* `DOMAIN`: The **Domain** of the Machine-to-Machine Application you created.
* `CLIENT_ID`: The **Client ID (Client ID: Identification value given to your registered resource from Auth0.)** of the Machine to Machine Application you created.
* `CLIENT_SECRET`: The **Client Secret** of the Machine-to-Machine Application you created.

```python lines expandable theme={null}
def main():
  import json, requests
  from requests.exceptions import RequestException, HTTPError, URLRequired

  # Configuration Values
  domain = 'YOUR_DOMAIN'
  audience = f'https://{domain}/api/v2/'
  client_id = '{yourClientId}'
  client_secret = '{yourClientSecret}'
  grant_type = "client_credentials" # OAuth 2.0 flow to use

  # Get an Access Token from Auth0
  base_url = f"https://{domain}"
  payload =  { 
    'grant_type': grant_type,
    'client_id': client_id,
    'client_secret': client_secret,
    'audience': audience
  }
  response = requests.post(f'{base_url}/oauth/token', data=payload)
  oauth = response.json()
  access_token = oauth.get('access_token')

  # Add the token to the Authorization header of the request
  headers = {
    'Authorization': f'Bearer {access_token}',
    'Content-Type': 'application/json'
  }

  # Get all Applications using the token
  try:
    res = requests.get(f'{base_url}/api/v2/clients', headers=headers)
    print(res.json())
  except HTTPError as e:
    print(f'HTTPError: {str(e.code)} {str(e.reason)}')
  except URLRequired as e:
    print(f'URLRequired: {str(e.reason)}')
  except RequestException as e:
    print(f'RequestException: {e}')
  except Exception as e:
    print(f'Generic Exception: {e}')

# Standard boilerplate to call the main() function.
if __name__ == '__main__':
  main()
```

## Learn more

* [Get Management API Access Tokens for Testing](/docs/docs/secure/tokens/access-tokens/management-api-access-tokens/get-management-api-access-tokens-for-testing)
* [Get Management API Access Tokens for Single-Page Applications](/docs/docs/secure/tokens/access-tokens/management-api-access-tokens/get-management-api-tokens-for-single-page-applications)
* [Applications in Auth0](/docs/docs/get-started/applications)
