Create a token

This page documents an earlier version of InfluxDB. InfluxDB v2.7 is the latest stable version. View this page in the v2.7 documentation.

Create API tokens using the InfluxDB user interface (UI), the influx command line interface (CLI), or the InfluxDB API.

Tokens are visible to the user who created the token. Users who own a token with Operator permissions also have access to all tokens. Tokens stop working when the user who created the token is deleted.

We recommend creating a generic user to create and manage tokens for writing data.

Manage tokens in the InfluxDB UI

To manage InfluxDB API Tokens in the InfluxDB UI, navigate to the API Tokens management page.

In the navigation menu on the left, select Data (Load Data) > Tokens.

Load Data

Create a token in the InfluxDB UI

  1. From the API Tokens management page, click Generate and select a token type (Read/Write Token or All Access API Token).
  2. In the window that appears, enter a description for your token in the Description field.
  3. If generating a read/write token:
    • Search for and select buckets to read from in the Read pane.
    • Search for and select buckets to write to in the Write pane.
  4. Click Save.

Create a token using the influx CLI

Use the influx auth create command to create a token. Include flags with the command to grant specific permissions to the token. See the available flags. Only tokens with the write: authorizations permission can create tokens.

  1. # Syntax
  2. influx auth create -o <org-name> [permission-flags]

Examples

Create an All-Access token

Create an All-Access token to grant permissions to all resources in an organization.

  1. influx auth create \
  2. --org my-org \
  3. --all-access

Create an Operator token

Create an Operator token to grant permissions to all resources in all organizations.

  1. influx auth create \
  2. --org my-org \
  3. --operator

Create a token with specified read permissions

  1. influx auth create \
  2. --org my-org \
  3. --read-bucket 03a2bbf46309a000 \
  4. --read-bucket 3a87c03ace269000 \
  5. --read-dashboards \
  6. --read-tasks \
  7. --read-telegrafs \
  8. --read-user

See the influx auth create documentation for information about other available flags.

Create a token using the InfluxDB API

Use the /api/v2/authorizations InfluxDB API endpoint to create a token.

  1. POST http://localhost:8086/api/v2/authorizations

Include the following in your request:

RequirementInclude by
API token with the write: authorizations permissionUse the Authorization header and the Bearer or Token scheme.
OrganizationPass as orgID in the request body.
Permissions listPass as a permissions array in the request body.
  1. INFLUX_ORG_ID=YOUR_ORG_ID
  2. INFLUX_TOKEN=YOUR_API_TOKEN
  3. curl -v --request POST \
  4. http://localhost:8086/api/v2/authorizations \
  5. --header "Authorization: Token ${INFLUX_TOKEN}" \
  6. --header 'Content-type: application/json' \
  7. --data '{
  8. "status": "active",
  9. "description": "iot-center-device",
  10. "orgID": "'"${INFLUX_ORG_ID}"'",
  11. "permissions": [
  12. {
  13. "action": "read",
  14. "resource": {
  15. "orgID": "'"${INFLUX_ORG_ID}"'",
  16. "type": "authorizations"
  17. }
  18. },
  19. {
  20. "action": "read",
  21. "resource": {
  22. "orgID": "'"${INFLUX_ORG_ID}"'",
  23. "type": "buckets"
  24. }
  25. },
  26. {
  27. "action": "write",
  28. "resource": {
  29. "orgID": "'"${INFLUX_ORG_ID}"'",
  30. "type": "buckets",
  31. "name": "iot-center"
  32. }
  33. }
  34. ]
  35. }'

Create a token scoped to a user

To scope a token to a user other than the token creator, pass userID in the request body.

  1. ######################################################
  2. # The example below uses common command-line tools
  3. # `curl`, `jq` with the InfluxDB API to do the following:
  4. # 1. Create a user.
  5. # 2. Find the new or existing user by name.
  6. # 3. If the user exists:
  7. # a. Build an authorization object with the user ID.
  8. # b. Create the new authorization.
  9. # c. Return the new token.
  10. ######################################################
  11. INFLUX_ORG_ID=YOUR_ORG_ID
  12. INFLUX_TOKEN=YOUR_API_TOKEN
  13. function create_token_with_user() {
  14. curl --request POST \
  15. "http://localhost:8086/api/v2/users/" \
  16. --header "Authorization: Token ${INFLUX_TOKEN}" \
  17. --header 'Content-type: application/json' \
  18. --data "{\"name\": \"$1\"}"
  19. curl --request GET \
  20. "http://localhost:8086/api/v2/users?name=$1" \
  21. --header "Authorization: Token ${INFLUX_TOKEN}" \
  22. --header 'Content-type: application/json' | \
  23. jq --arg USER $1 '.users[0] // error("User missing")
  24. | {
  25. "orgID": "'"${INFLUX_ORG_ID}"'",
  26. "userID": .id,
  27. "description": $USER,
  28. "permissions": [
  29. {"action": "read", "resource": {"type": "buckets"}}
  30. ]
  31. }' | \
  32. curl --request POST \
  33. "http://localhost:8086/api/v2/authorizations" \
  34. --header "Authorization: Token ${INFLUX_TOKEN}" \
  35. --header 'Content-type: application/json' \
  36. --data @- | \
  37. jq '.token'
  38. }
  39. create_token_with_user 'iot_user_1'

See the POST /api/v2/authorizations documentation for more information about options.