Documentation

influxdb.api() function

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.

Data type: String

path

(Required) InfluxDB API path.

Data type: String

host

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

Data type: String

token

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

Data type: String

headers

HTTP request headers.

Data type: Dictionary

query

URL query parameters.

Data type: Dictionary

timeout

HTTP request timeout. Default is 30s.

Data type: Duration

body

HTTP request body as bytes.

Data type: 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\": []
  }")
)

Set your InfluxDB URL

Upgrade to InfluxDB Cloud or InfluxDB 2.0!

InfluxDB Cloud and InfluxDB OSS 2.0 ready for production.