Documentation

Create a token

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.

Create a token in the InfluxDB UI

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

  2. Click Generate and select a token type (Read/Write Token or All-Access Token).

  3. In the window that appears, enter a description for your token in the Description field.

  4. 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.
  5. 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.

# Syntax
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.

influx auth create \
  --org my-org \
  --all-access

Create an Operator token

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

influx auth create \
  --org my-org \
  --operator

Create a token with specified read permissions

influx auth create \
  --org my-org \
  --read-bucket 03a2bbf46309a000 \
  --read-bucket 3a87c03ace269000 \
  --read-dashboards \
  --read-tasks \
  --read-telegrafs \
  --read-user

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

Create a token using the InfluxDB API

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

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.
INFLUX_ORG_ID=YOUR_ORG_ID
INFLUX_TOKEN=YOUR_API_TOKEN

curl -v --request POST \
  http://localhost:8086/api/v2/authorizations \
  --header "Authorization: Token ${INFLUX_TOKEN}" \
  --header 'Content-type: application/json' \
  --data '{
  "status": "active",
  "description": "iot-center-device",
  "orgID": "'"${INFLUX_ORG_ID}"'",
  "permissions": [
    {
      "action": "read",
      "resource": {
        "type": "authorizations"
      }
    },
    {
      "action": "read",
      "resource": {
        "type": "buckets"
      }
    },
    {
      "action": "write",
      "resource": {
        "type": "buckets",
        "name": "iot-center" 
      }
    }
  ]
}'


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.

######################################################
# The example below uses common command-line tools 
# `curl`, `jq` with the InfluxDB API to do the following:
# 1. Create a user.
# 2. Find the new or existing user by name.
# 3. If the user exists:
#   a. Build an authorization object with the user ID.
#   b. Create the new authorization.
#   c. Return the new token.
######################################################

INFLUX_TOKEN=YOUR_API_TOKEN

function create_token_with_user() {
  curl --request POST \
    "http://localhost:8086/api/v2/users/" \
    --header "Authorization: Token ${INFLUX_TOKEN}" \
    --header 'Content-type: application/json' \
    --data "{\"name\": \"$1\"}"
  
  curl --request GET \
    "http://localhost:8086/api/v2/users?name=$1" \
    --header "Authorization: Token ${INFLUX_TOKEN}" \
    --header 'Content-type: application/json' | \
  
  jq --arg USER $1 '.users[0] // error("User missing")
    | {
        "orgID": "YOUR_ORG_ID",
        "userID": .id,
        "description": $USER,
        "permissions": [
           {"action": "read", "resource": {"type": "buckets"}}
         ]
      }' | \
  
  curl --request POST \
    "http://localhost:8086/api/v2/authorizations" \
    --header "Authorization: Token ${INFLUX_TOKEN}" \
    --header 'Content-type: application/json' \
    --data @- | \
  
  jq '.token'
}

create_token_with_user 'iot_user_1'

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


Set your InfluxDB URL

Upgrade to InfluxDB Cloud or InfluxDB 2.0!

InfluxDB Cloud and InfluxDB OSS 2.0 ready for production.