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.
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.
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"),
)
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\": []
}",
),
)
Support and feedback
Thank you for being part of our community! We welcome and encourage your feedback and bug reports for Flux and this documentation. To find support, the following resources are available:
InfluxDB Cloud customers can contact InfluxData Support.