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
- Configure a custom API token
- Review and create your API token
- Copy and test your API token
Access the Create API Token page
To access the Create Custom Token page, follow these steps:
- Log in to your Cloudflare account and select My Profile from the user account drop-down list.
In your user profile page, select the API Tokens tab.
In the API Tokens page, click Create Token.
The Create API Token page displays.
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:
- Click Get started in the Custom token section of the Create API Token page:
The Create Custom Token page displays:
Enter a descriptive name for your token in the Token name text input field.
To configure access to the GraphQL Analytics API, use the Permissions drop-down lists. To set permissions for the GraphQL Analytics API, select Analytics from the second drop-down list.
This example scopes zone-level permissions for read access to the Analytics API:
- 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:
- [Optional] To restrict the API token to specific IP addresses, use the IP Address Filtering controls.
- To define how long the token is valid, click the TTL (time-to-live) start/end date picker.
- Click 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 click 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.
Once you have validated your API token configuration, click 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.
To copy the token to your device’s clipboard, click the Copy button.
To test your token, copy the curl
command and paste it into a terminal.
When you have finished, click View all API tokens.