Skip to content

Configure an Analytics API token

Cloudflare recommends API tokens as the preferred authentication method with Cloudflare APIs. This article walks through creating API tokens for authentication to the GraphQL Analytics API.

For more details on API tokens and the full range of supported options, refer to Creating API tokens.

To create an API token for authentication to the GraphQL Analytics API, use this workflow:

Access the Create API Token page

To access the Create Custom Token page, follow these steps:

  1. Log in to your Cloudflare account and select My Profile from the user account drop-down list.

User account drop-down menu

  1. In your user profile page, select the API Tokens tab.

  2. In the API Tokens page, select Create Token.

API Tokens tab

The Create API Token page displays.

Clicking Get started in the Create API Token page

The next section of this walkthrough shows you how to configure a custom token for access to the GraphQL Analytics API.

Configure a custom API token

To configure a custom token, follow these steps:

  1. Select Get started in the Custom token section of the Create API Token page:

Clicking Get started in the Create API Token page

The Create Custom Token page displays:

Create Custom Token page

  1. Enter a descriptive name for your token in the Token name text input field.

  2. To configure access to the GraphQL Analytics API, use the Permissions drop-down lists.

  3. To set permissions for the GraphQL Analytics API, select Account in the first drop-down list, Account Analytics from the second drop-down list, and Read from the third.

This example scopes account-level permissions for read access to the Analytics API:

Permissions configuration page

  1. To configure the specific zones to which the token grants access, use the Zone Resources drop-down lists. In this example, the token is set to grant access to all zones:

Resources configuration page

  1. To restrict the API token to specific IP addresses, use the Client IP Address Filtering controls.

IP Address Filtering configuration page

  1. To define how long the token is valid, select the TTL (time-to-live) start/end date.

TTL configuration page

  1. Select Continue to summary.

The next section of this walkthrough covers how to review and test your API token.

Review and create your API token

Once you select Continue to summary, the API Token Summary page displays.

Use the API Token Summary to confirm that you have scoped the API Token to the desired permissions and resources before creating it.

API Token Summary page

Once you have validated your API token configuration, select Create Token.

Copy and test your API token

When you create a new token, a confirmation page displays that includes your token and a custom curl command.

Page displaying your API token and the curlcommand to test your token

To copy the token to your device’s clipboard, select the Copy button.

To test your token, copy the curl command and paste it into a terminal.

When you have finished, select View all API tokens.