Documentation

influxdb.api() function

influxdb.api() is experimental and subject to change at any time.

influxdb.api() submits an HTTP request to the specified InfluxDB API path and returns a record containing the HTTP status code, response headers, and the response body.

Note: influxdb.api() uses the authorization of the specified token or, if executed from the InfluxDB UI, the authorization of the InfluxDB user that invokes the script. Authorization permissions and limits apply to each request.

Response format

influxdb.api() returns a record with the following properties:

  • statusCode: HTTP status code returned by the GET request (int).
  • headers: HTTP response headers (dict).
  • body: HTTP response body (bytes).
Function type signature
(
    method: string,
    path: string,
    ?body: bytes,
    ?headers: [string:string],
    ?host: string,
    ?query: [string:string],
    ?timeout: duration,
    ?token: string,
) => {statusCode: int, headers: [string:string], body: bytes}

For more information, see Function type signatures.

Parameters

method

(Required) HTTP request method.

path

(Required) InfluxDB API path.

host

InfluxDB host URL (Required when executed outside of InfluxDB). Default is "".

token

InfluxDB API token (Required when executed outside of InfluxDB). Default is "".

headers

HTTP request headers.

query

URL query parameters.

timeout

HTTP request timeout. Default is 30s.

body

HTTP request body as bytes.

Examples

Retrieve the health of an InfluxDB OSS instance

import "experimental/influxdb"
import "influxdata/influxdb/secrets"

token = secrets.get(key: "INFLUX_TOKEN")

response = influxdb.api(method: "get", path: "/health", host: "http://localhost:8086", token: token)

string(v: response.body)

Create a bucket through the InfluxDB Cloud API

import "experimental/influxdb"
import "json"
import "influxdata/influxdb/secrets"

token = secrets.get(key: "INFLUX_TOKEN")

influxdb.api(
    method: "post",
    path: "/api/v2/buckets",
    host: "https://us-west-2-1.aws.cloud2.influxdata.com",
    token: token,
    body:
        json.encode(
            v: {
                name: "example-bucket",
                description: "This is an example bucket.",
                orgID: "x000X0x0xx0X00x0",
                retentionRules: [],
            },
        ),
)

Was this page helpful?

Thank you for your feedback!


The future of Flux

Flux is going into maintenance mode. You can continue using it as you currently are without any changes to your code.

Read more

InfluxDB v3 enhancements and InfluxDB Clustered is now generally available

New capabilities, including faster query performance and management tooling advance the InfluxDB v3 product line. InfluxDB Clustered is now generally available.

InfluxDB v3 performance and features

The InfluxDB v3 product line has seen significant enhancements in query performance and has made new management tooling available. These enhancements include an operational dashboard to monitor the health of your InfluxDB cluster, single sign-on (SSO) support in InfluxDB Cloud Dedicated, and new management APIs for tokens and databases.

Learn about the new v3 enhancements


InfluxDB Clustered general availability

InfluxDB Clustered is now generally available and gives you the power of InfluxDB v3 in your self-managed stack.

Talk to us about InfluxDB Clustered