Postlad/Guides/Send sensor data over HTTP
Send sensor data over HTTP from any language
Anything that can make a web request can log a reading: a shell script, a Python job, a Node service, a PowerShell task or a MicroPython board. This page has the same one-line request in each of them, copy-and-paste ready, plus what every reply means.
Every snippet on this page was run against a local copy of the Postlad ingest service on 2026-11-06, and the replies shown are the replies it gave. The MicroPython program was run under desktop Python with stand-ins for its two board modules, not on a board.
The one line
A reading is one GET request. The write key says which stream it belongs to; the fields carry the numbers.
http://api.postlad.com/u?k=YOUR_KEY&f1=23.5&f2=61The reply is plain text. ok 1 means stored, and the number counts the readings your account has stored this month. Anything that was not stored gets an HTTP status of 400 or above and one sentence that says what to do next.
| Parameter | What it is | Required |
|---|---|---|
k | The stream's write key, from the stream's page in the dashboard | Yes |
f1 to f16 | Up to sixteen numbers. Plain decimals: 23.5, -4, 2.3e-3 | At least one field or a status |
t | When the reading was taken, as Unix seconds or milliseconds, within 7 days of now. Leave it out and the server's clock is used | No |
status | A short text note, up to 120 bytes, such as batt=3.7V. Only the latest one is kept | No |
fmt | json for a JSON reply instead of plain text | No |
Those five names are the whole vocabulary. A parameter Postlad does not know is refused rather than ignored, so a typo cannot produce a stream that says ok and stays empty:
error unknown_param: "temp" is not a parameter Postlad understands. Valid: k, f1..f16, t, status, fmt. Did you mean f1=?curl: the first reading
Create a stream, copy its write key, and paste this into a terminal. It works the same on Linux, macOS and Windows 10 or later, which all ship curl.
curl "http://api.postlad.com/u?k=YOUR_KEY&f1=23.5&f2=61"ok 1Open the stream's page and the point is on the chart. When a value has characters that need escaping, such as the comma and spaces in a status note, let curl encode it:
curl -G "http://api.postlad.com/u" \
--data-urlencode "k=YOUR_KEY" \
--data-urlencode "f1=20.5" \
--data-urlencode "status=batt=3.7V, rssi=-71"Python, with no packages
The standard library is enough. This works on Python 3.8 or later, including on a Raspberry Pi.
# send.py - one reading to Postlad, Python 3 standard library only
import urllib.error
import urllib.parse
import urllib.request
POSTLAD_URL = "http://api.postlad.com/u"
WRITE_KEY = "YOUR_KEY"
def send(**fields):
query = urllib.parse.urlencode({"k": WRITE_KEY, **fields})
try:
with urllib.request.urlopen(f"{POSTLAD_URL}?{query}", timeout=10) as reply:
print(reply.status, reply.read().decode().strip())
return True
except urllib.error.HTTPError as err:
# Postlad answers every refusal with one sentence that says what to do.
print(err.code, err.read().decode().strip())
return False
send(f1=23.5, f2=61)200 ok 2urlencode takes care of escaping. A refusal raises HTTPError, whose body is the sentence explaining it, which is why the program prints it instead of a stack trace. For a long-running logger with buffering and a systemd service, see the Raspberry Pi data logger guide.
Node.js
Node 18 and later have fetch built in. Save as send.mjs and run node send.mjs.
// send.mjs - one reading to Postlad, Node.js 18+ (built-in fetch)
const POSTLAD_URL = "http://api.postlad.com/u";
const WRITE_KEY = "YOUR_KEY";
const url = new URL(POSTLAD_URL);
url.search = new URLSearchParams({ k: WRITE_KEY, f1: 23.5, f2: 61 });
const reply = await fetch(url);
console.log(reply.status, (await reply.text()).trim());fetch does not throw on a 400 or a 429, so check reply.status: 200 is the only answer that means the reading was stored.
PowerShell on Windows
Works in the PowerShell 5.1 that ships with Windows and in PowerShell 7.
# send.ps1 - one reading to Postlad, Windows PowerShell 5.1 or PowerShell 7
$WriteKey = "YOUR_KEY"
$Uri = "http://api.postlad.com/u?k=$WriteKey&f1=23.5&f2=61"
try {
$reply = Invoke-WebRequest -Uri $Uri -UseBasicParsing
Write-Output "$($reply.StatusCode) $($reply.Content.Trim())"
} catch {
Write-Output "not stored: $($_.ErrorDetails.Message)"
}A refused reading lands in the catch block, and ErrorDetails.Message holds Postlad's sentence:
not stored: error bad_key: no stream matches that write key. Check k= for a typo, or copy the key again from https://app.postlad.com/streams.To log something every five minutes, put the script in Task Scheduler with a repeating trigger rather than writing a loop that has to survive restarts.
A shell loop on Linux or a Raspberry Pi
This sends the processor temperature every minute. It is a useful first stream on a Pi because it needs no wiring at all.
#!/bin/sh
# loop.sh - send the CPU temperature of a Linux machine every 60 seconds
WRITE_KEY="YOUR_KEY"
while true; do
# /sys reports millidegrees: 48312 means 48.312 °C
CPU=$(awk '{ printf "%.1f", $1 / 1000 }' /sys/class/thermal/thermal_zone0/temp)
curl -sS --max-time 10 "http://api.postlad.com/u?k=$WRITE_KEY&f1=$CPU"
sleep 60
doneOr skip the loop and let cron run it once a minute (crontab -e, one line):
* * * * * curl -sS --max-time 10 "http://api.postlad.com/u?k=YOUR_KEY&f1=$(awk '{ printf "\%.1f", $1 / 1000 }' /sys/class/thermal/thermal_zone0/temp)" > /dev/nullThe % signs are escaped because cron treats a bare % as a newline.
MicroPython on an ESP32 or a Pico W
urequests is included in the standard MicroPython builds for both boards. Save this as main.py on the board.
# main.py - MicroPython on an ESP32 or a Raspberry Pi Pico W
import network
import time
import urequests
WIFI_SSID = "YOUR_WIFI_NAME"
WIFI_PASSWORD = "YOUR_WIFI_PASSWORD"
WRITE_KEY = "YOUR_KEY"
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(WIFI_SSID, WIFI_PASSWORD)
while not wlan.isconnected():
time.sleep(0.5)
print("Wi-Fi joined:", wlan.ifconfig()[0])
def read_sensor():
return 23.5 # replace with your sensor's reading
while True:
url = "http://api.postlad.com/u?k={}&f1={:.2f}".format(WRITE_KEY, read_sensor())
try:
reply = urequests.get(url)
print(reply.status_code, reply.text.strip())
reply.close()
except OSError as err:
print("network error, will try again:", err)
time.sleep(60)For a full Pico W project with a real sensor, wiring and a version that uses raw sockets, see the Pico W cloud data logger. For C++ on an ESP32 or ESP8266, start with Send ESP32 data to the cloud, or let the device setup wizard write a complete program for your board and sensor.
POST, JSON and keeping the key out of the URL
The same endpoint accepts POST, either as JSON or as a form. The reply to a JSON request is JSON:
curl -X POST "http://api.postlad.com/u" \
-H "Content-Type: application/json" \
-d '{"k":"YOUR_KEY","f1":23.6,"f2":60}'{"ok":true,"stored":1,"month_points":2,"stream":"desk-test","ts":1794024172996}Proxies and web servers often log full URLs. If yours does, send the key as a header instead, and it stays out of the log line:
curl -H "Authorization: Bearer YOUR_KEY" "https://api.postlad.com/u?f1=20.1"Timestamps and batches
A reading taken earlier can carry its own time with t, in Unix seconds or milliseconds, up to 7 days back:
# a reading taken an hour ago
curl "http://api.postlad.com/u?k=YOUR_KEY&f1=19.2&t=$(( $(date +%s) - 3600 ))"A device that was offline can send up to 100 buffered readings in one request to /u/batch. Every point needs a t:
# three readings, two minutes ago, one minute ago and now
NOW=$(date +%s)
curl -X POST "http://api.postlad.com/u/batch" \
-H "Content-Type: application/json" \
-d "{\"k\":\"YOUR_KEY\",\"points\":[
{\"t\":$((NOW - 120)),\"f1\":21.9},
{\"t\":$((NOW - 60)),\"f1\":22.1},
{\"t\":$NOW,\"f1\":22.4}]}"{"ok":true,"stored":3,"updated":0,"month_points":11,"stream":"desk-test","first_ts":1794024103000,"last_ts":1794024223000}Sending the same batch again is safe. A point with a timestamp that is already stored overwrites it instead of being added twice, and the reply says so with "stored":0,"updated":3. The store and forward guide builds a complete buffer around this.
What the replies mean
| Status | Meaning | What your code should do |
|---|---|---|
| 200 | Stored | Carry on |
| 400 | The request itself is wrong: a missing key, a field that is not a number, an unknown parameter | Do not retry. Print the sentence and fix the code |
| 401, 403 | The key is wrong, rotated, or the stream is read-only | Do not retry. Copy the key again from the stream's page |
| 429 | Too fast for the stream's rate, or the month's allowance is used | Wait for the number of seconds in the Retry-After header, then resend |
| 503 | Postlad could not store it. Our fault, not yours | Keep the reading and retry in 30 seconds |
Postlad never answers 200 for a reading it did not store, so a program that treats 200 as the only success can never lose a point without knowing. Every sentence, with its code, is listed in the error catalogue.
How often to send
A stream accepts one reading every 5 seconds on the Free plan. The real limit for continuous logging is the account's monthly allowance of 100,000 readings, shared by all its streams:
| One stream sending every | Readings in a 31-day month | Fits in Free |
|---|---|---|
| 5 seconds | 535,680 | No, about 6 days' worth |
| 30 seconds | 89,280 | Yes |
| 60 seconds | 44,640 | Yes, twice over |
| 5 minutes | 8,928 | Yes |
Up to sixteen fields in one request count as one reading, so send temperature, humidity and pressure together rather than as three requests. On Free, every reading is kept at full detail for 30 days, then an hourly minimum, maximum and average for 12 months. The pricing page has the other plans.
Plain HTTP or HTTPS
Both work, on the same address. Plain http:// is supported on purpose, because the smallest boards have no room for a certificate store, and it never redirects. The trade-off is that anyone who can watch the network can read the reading and the key. Use https:// from anything that can: a computer, a Raspberry Pi, a server. A stream can also be set to refuse plain HTTP altogether.
FAQ
Do I need an SDK, a library or an MQTT broker?
No. A reading is one ordinary HTTP request, so the HTTP client your language already has is enough.
Can I send several values at once?
Yes. Put up to sixteen numbers in f1 to f16 of the same request. They are stored as one reading with one timestamp.
What happens if I send too fast?
The reading is refused with HTTP 429, a Retry-After header and a sentence saying when to resend. It is not stored and not silently dropped, so your code knows to keep it.
Can I name the fields, like temperature instead of f1?
Yes, on the stream's page in the dashboard. Names, units and decimals change the chart, the share page and the CSV export. The device keeps sending f1, f2 and so on.
Can I read the data back from a script?
Yes. Every stream has a JSON read API and a CSV export, documented in the API reference. A read key lets a script read a private stream without being able to write to it.
Get a write key
Create a free account, make a stream, and the first curl line above will put a point on its chart.
Related guides
- Send ESP32 data to the cloud: the same request from an Arduino sketch.
- Raspberry Pi data logger online: Python with a service and an offline buffer.
- Tasmota, Shelly and Home Assistant: send readings from smart-home devices without writing a program.
- Embed a live sensor chart: put the stream on your own website.
- Sensor data in Google Sheets: pull the readings into a spreadsheet with one formula.
- Store and forward after an outage: buffering and batch catch-up.
Sources and verification
- The request, the replies and the error sentences are those of the Postlad ingest service, run locally from the same code that serves
api.postlad.com. - Full API reference: app.postlad.com/docs/api.