Prerequisites:

To create API token,

  1. From the Cloudflare dashboard, go to My Profile > API Tokens for User tokens. For creating Account Tokens, go to Manage Account > API Tokens.
  2. Select Create Token.
  3. Select Edit zone DNS template.
  4. Add or edit the token name to add an appropriate name for the token.
  5. Select Zones to Include for token access. (add one or multiple zones)
  6. Select Continue to summary.
  7. Review the token summary. Select Edit to make adjustments, or you can also edit the settings after token creation.
  8. Select Create Token to generate the token's secret.
  9. Copy the secret and store it securely. The token secret is only shown once.
  10. The token is created successfully, and you can start working with the Cloudflare API.