The HTTP API
Outcome: the same write and the same
query the CLI did, done with nothing
but curl — plus the two error answers
worth meeting on purpose.
Transcript:
influxdb-lab/transcripts/t04-http-api.txt.
Why bother, when the CLI exists
Because the CLI is a convenience, not
the product. Every program that feeds
InfluxDB — sensors, scripts in other
languages, Telegraf, your own code —
speaks this API: two endpoints carry
nearly everything. /api/v2/write
takes line protocol in and
/api/v2/query takes Flux in. The
token rides in one header:
Authorization: Token <value>. Learn
these two calls and you can feed
InfluxDB from anything that can make
an HTTP request, including a
microcontroller.
The write: 204 and silence
curl -s -X POST \
"http://127.0.0.1:18084/api/v2/write?org=example-org&bucket=weather&precision=s" \
-H "Authorization: Token $TOKEN" \
-H "Content-Type: text/plain; charset=utf-8" \
--data-binary @http-point.lp
The answer is HTTP status: 204 — No
Content, the API's entire success
vocabulary. Organisation and bucket are
named in the URL; precision likewise,
which is why the lab's point
(weather,station=http-1
temperature=22.4,humidity=44i, plus its
timestamp) needed no other ceremony.
The query: Flux in, CSV out
curl -s -X POST \
"http://127.0.0.1:18084/api/v2/query?org=example-org" \
-H "Authorization: Token $TOKEN" \
-H "Content-Type: application/vnd.flux" \
-H "Accept: application/csv" \
--data-binary 'from(bucket: "weather")
|> range(start: -1h)
|> filter(fn: (r) => r._field == "temperature" and r.station == "http-1")'
,result,table,_start,_stop,_time,_value,_field,_measurement,station
,_result,0,2026-11-01T02:16:36Z,2026-11-01T03:16:36Z,2026-11-01T03:16:36Z,22.4,temperature,weather,http-1
The answer is annotated CSV: a
header row, then one row per point,
with the query's own _start and
_stop repeated on every row, and
blank lines between tables. It is not
the prettiest format in the building,
but it is the format — every client
library is, underneath, a reader of
these rows. (Ask for Accept:
application/json instead and v2 will
decline; CSV is the contract.)
The errors, met on purpose
Two failures, arranged deliberately:
A wrong token earns the door slammed before anything is read:
{"code":"unauthorized","message":"unauthorized access"}
HTTP status: 401
A malformed line earns something
better — a diagnosis. The lab sent
weather temperature=hot 1793502996
(a space where the tag comma belongs,
and an unquoted word as a value):
{"code":"invalid","message":"unable to parse 'weather temperature=hot 1793502996': invalid boolean"}
HTTP status: 400
The server parsed the line its own way
— temperature=hot landed where a
field with a boolean value was
expected — and said so, quoting the
line. Two working rules follow. Quote
your string fields (name="hot" would
have parsed, then been judged as a
type error against the numeric field —
a different, equally specific refusal).
And read the whole message before
fixing the line: InfluxDB's parse
errors name the exact text they
choked on, which makes them the
fastest debugging partner in this
guide. Chapter 7 adds the third and
fourth codes — 403 for a known token
without the power, 404 for a bucket
the token cannot see — and together
the four are a complete vocabulary
for "no".