New: the AI firewall watches the whole platform and explains each incident in plain words. See how it works

Reply To: Raspberry Pi polling the latest tank level over the API keeps getting 401

Brian’s right, and you’re also missing the organisation prefix. I set up nearly the same thing for a chiller room last year.

1. API Keys (Developer menu) > New API Key. Under Module permissions give it read-only telemetry, nothing else. Set an IP allowlist to the office’s address, and note the expiry, default is 90 days, a year at most. Put a reminder in the calendar, ours expired on a Saturday.

2. Every management path sits under the tenant:

GET https://<host>/tenant/<tenantId>/api/telemetry/latest?kind=iot_device&entityId=<deviceId>&keys=level_pct
Authorization: Bearer sk_live_...

Answer looks like {“latest”: {“level_pct”: {“ts”: …, “value”: 91.2}}}. Compare the ts with the previous one so you don’t buzz twice on the same reading.

3. Handle 429 and wait the Retry-After seconds. Poll every 30 s or so, the tank doesn’t fill in 5.

The other route, if you want it instant: make the Pi a device itself, have a rule on the tank send it a command when level_pct rises above 90, and let the Pi wait on GET /api/v1/rpc with its own device token. More moving parts, no polling. For a buzzer I’d take the API key. Conventions are on REST API basics.

Accepted solution♥ 5