Documentation

influxdb.api() function

Flux 0.114.0+

The influxdb.api() function is experimental and subject to change at any time. By using this function, you accept the risks of experimental functions.

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

import "experimental/influxdb"

influxdb.api(
  method: "get",
  path: "/example",
  host: "http://localhost:8086",
  token: "mySupeR53cre7t0k3n",
  headers: ["header1": "header1Value", "header2": "header2Value"],
  query: ["ex1": "example1", "ex2": "example2"],
  timeout: 30s,
  body: bytes(v: "Example body")
)

View response record schema

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)

// Returns something similar to:
// {
//   "name":"influxdb",
//   "message":"ready for queries and writes",
//   "status":"pass",
//   "checks":[],
//   "version": "dev",
//   "commit": "000xX0xx0X"
// }
Create a bucket through the InfluxDB API
import "experimental/influxdb"
import "influxdata/influxdb/secrets"

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

influxdb.api(
  method: "post",
  path: "/api/v2/buckets",
  host: "http://localhost:8086",
  token: token,
  body: bytes(v: "{
    \"name\": \"example-bucket\",
    \"description\": \"This is an example bucket.\",
    \"orgID\": \"x000X0x0xx0X00x0\",
    \"retentionRules\": []
  }")
)

Upgrade to InfluxDB Cloud or InfluxDB 2.0!

InfluxDB Cloud and InfluxDB OSS 2.0 ready for production.