The HTTP API is the primary means for querying data in InfluxDB.

To perform a query send a GET request to the /query endpoint, set the URL parameter db as the target database, and set the URL parameter q as your query.

1
curl -G 'http://localhost:8086/query?pretty=true' --data-urlencode "db=mydb" --data-urlencode "q=SELECT \"value\" FROM \"cpu_load_short\" WHERE \"region\"='us-west'"

InfluxDB returns JSON. The results of your query appear in the 'result' array. If an error occurs, InfluxDB sets an 'error' key with an explanation of the error.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
{
"results": [
{
"statement_id": 0,
"series": [
{
"name": "cpu_load_start",
"columns": [
"time",
"value"
],
"values": [
[
"2015-01-29T21:55:43.702900257Z",
2
],
[
"2015-01-29T21:55:43.702900257Z",
0.55
],
[
"2015-06-11T20:46:02Z",
0.64
]
]
}
]
}
]
}

Note: Appending pretty=true to the URL enables pretty-printed JSON output. While this is useful for debugging or when queryting directly with tools like curl, it is not recommended for production use as it consumes unnecessary network bandwidth.

Multiple queries

Send multiple queries to InfluxDB in a single API call. Simply delimit each query using a semicolon

1
curl -G 'http://localhost:8086/query?pretty=true' --data-urlencode "db=mydb" --data-urlencode "q=SELECT \"value\" FROM \"cpu_load_short\" WHERE \"region\"='us-west';SELECT count(\"value\") FROM \"cpu_load_short\" WHERE \"region\"='us-west'"