Raspberry Pi polling the latest tank level over the API keeps getting 401
New to the IoT side of things, I’m a backend dev and got handed this.
We have a tank level sensor already reporting to Hermetry (device “tank-01”, key level_pct). Someone wants a Pi in the office that sounds a buzzer when the level goes over 90. My plan was a tiny Python service on the Pi that polls Hermetry every 5 seconds for the latest value. I copied the access token from tank-01’s page and did:
GET https://<host>/api/telemetry/latest?kind=iot_device&entityId=6f1c...&keys=level_pct
Authorization: Bearer <tank-01 token>
-> 401
Tried with and without “Bearer”, same. Is the token wrong or is this the wrong endpoint?
That’s a device credential. It logs a device in, it doesn’t read anything for you. The management API wants an API key. Also every 5 seconds is a lot for a buzzer.
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.
That was two bugs, the token and the missing /tenant/<tenantId> bit (got a 404 once I had the key, then saw it). Running at 30 s now with a read-only key locked to our IP. Buzzer went off this morning when they filled it, so it works.
Store the key in a root-only file, not in the script you’ll paste into a ticket some day.
- You must be logged in to reply to this topic.
Join the conversation
Sign in to ask and answer, like helpful posts and mark the reply that solved your problem. Every contribution earns points and levels.

