Authentication

Use one of the following schemes to authenticate to the InfluxDB Cloud API:

  • Token authentication
  • Basic authentication
  • Querystring authentication

Basic Authentication

Basic authentication scheme

Use the HTTP Basic authentication scheme for InfluxDB /api/v2 API operations that support it:

Syntax

Authorization: Basic BASE64_ENCODED_CREDENTIALS

To construct the BASE64_ENCODED_CREDENTIALS, combine the username and the password with a colon (USERNAME:PASSWORD), and then encode the resulting string in base64. Many HTTP clients encode the credentials for you before sending the request.

Warning: Base64-encoding can easily be reversed to obtain the original username and password. It is used to keep the data intact and does not provide security. You should always use HTTPS when authenticating or sending a request with sensitive information.

Examples

In the examples, replace the following:

  • EMAIL_ADDRESS: InfluxDB Cloud username (the email address the user signed up with)
  • PASSWORD: InfluxDB Cloud API token
  • INFLUX_URL: your InfluxDB Cloud URL

Encode credentials with cURL

The following example shows how to use cURL to send an API request that uses Basic authentication. With the --user option, cURL encodes the credentials and passes them in the Authorization: Basic header.

curl --get "INFLUX_URL/api/v2/signin"
    --user "EMAIL_ADDRESS":"PASSWORD"

Encode credentials with Flux

The Flux http.basicAuth() function returns a Base64-encoded basic authentication header using a specified username and password combination.

Encode credentials with JavaScript

The following example shows how to use the JavaScript btoa() function to create a Base64-encoded string:

btoa('EMAIL_ADDRESS:PASSWORD')

The output is the following:

'VVNFUk5BTUU6UEFTU1dPUkQ='

Once you have the Base64-encoded credentials, you can pass them in the Authorization header–for example:

curl --get "INFLUX_URL/api/v2/signin"
    --header "Authorization: Basic VVNFUk5BTUU6UEFTU1dPUkQ="

To learn more about HTTP authentication, see Mozilla Developer Network (MDN) Web Docs, HTTP authentication._

Query String Authentication

Use the query string authentication scheme with InfluxDB v1-compatible API operations. Pass your InfluxDB Cloud email address and API token as query parameters using u for username and p for password (API token).

Syntax

?u=EMAIL_ADDRESS&p=INFLUX_API_TOKEN

Example

curl --get "INFLUX_URL/query" \
    --data-urlencode "u=EMAIL_ADDRESS" \
    --data-urlencode "p=INFLUX_API_TOKEN" \
    --data-urlencode "q=SHOW DATABASES"

Replace the following:

  • INFLUX_URL: your InfluxDB Cloud URL
  • EMAIL_ADDRESS: your InfluxDB Cloud email address
  • INFLUX_API_TOKEN: your InfluxDB API token

Query string authentication exposes your credentials in the URL and server logs. Use Token authentication for production environments.

Token Authentication

Use the Token authentication scheme to authenticate to the InfluxDB API.

In your API requests, send an Authorization header. For the header value, provide the word Token followed by a space and an InfluxDB API token. The word Token is case-sensitive.

Syntax

Authorization: Token INFLUX_API_TOKEN

Example

Use Token authentication with cURL

The following example shows how to use cURL to send an API request that uses Token authentication:

curl --request GET "INFLUX_URL/api/v2/buckets" \
     --header "Authorization: Token INFLUX_API_TOKEN"

Replace the following:


Was this page helpful?

Thank you for your feedback!