terra-api-webhooks
FreeRuns bundled scriptsNot checkedReceive and verify Terra API webhooks (tryterra.co wearables and health data). Use when setting up a Terra webhook destination, debugging X-Terra-Signature…
by hookdeck★ 104 GitHub starsAbout this skill
Terra API Webhooks
When to Use This Skill
- How do I receive Terra API webhooks?
- How do I verify the
X-Terra-Signatureheader (t=...,v1=...)? - How do I handle Terra
auth,deauthoractivityevents? - Why is my Terra webhook signature verification failing?
- How do I dispatch on the
typefield of a Terra webhook body?
Essential Code (USE THIS)
Terra signs every delivery with the X-Terra-Signature header. Terra's own agent skills say it also still sends a deprecated Terra-Signature duplicate, so read X-Terra-Signature and fall back to terra-signature:
X-Terra-Signature: t=1723808700,v1=a5ee9dba96b4f65aeff6c841aa50121b1f73ec7990d28d53b201523776d4eb00
tis the Unix timestamp (seconds). Use it as the string in the header; never parse and re-format it.v1is lowercase hex HMAC-SHA256 of"<t>.<raw body>". The key is the webhook's signing secret as UTF-8 bytes (not hex- or base64-decoded). Terra says the header carries one or more signatures: accept the delivery if anyv1matches. Ignore other keys such asv0.- The event name is the top-level
typefield in the JSON body;statusqualifies it. - Missing header, no
t, malformed or non-matching signature: return401.
Verification (Node.js)
const crypto = require('crypto');
// rawBody: Buffer of the exact request bytes (express.raw({ type: '*/*' }), not express.json)
function verifyTerra(rawBody, header, secret) {
if (!secret || !header) return false;
let t;
const sigs = [];
for (const item of header.split(',')) {
const i = item.indexOf('=');
if (i <= 0) continue;
const key = item.slice(0, i).trim(), value = item.slice(i + 1).trim();
if (key === 't' && t === undefined) t = value;
else if (key === 'v1') sigs.push(value);
}
if (!t || sigs.length === 0) return false;
const expected = Buffer.from(
crypto.createHmac('sha256', secret).update(`${t}.`).update(rawBody).digest('hex'));
// Check length and alphabet first; never Buffer.from(sig, 'hex') on unvalidated input
return sigs.some((s) => /^[0-9a-fA-F]{64}$/.test(s) &&
crypto.timingSafeEqual(Buffer.from(s.toLowerCase()), expected));
}
Verification (Python)
import hashlib, hmac, re
def verify_terra(raw_body: bytes, header, secret: str) -> bool:
if not secret or not header:
return False
t, sigs = None, []
for item in header.split(","):
key, sep, value = item.partition("=")
key, value = key.strip(), value.strip()
if not sep or not key:
continue
if key == "t" and t is None:
t = value
elif key == "v1":
sigs.append(value.encode())
if not t or not sigs:
return False
expected = hmac.new(secret.encode(), t.encode() + b"." + raw_body, hashlib.sha256).hexdigest().encode()
return any(re.fullmatch(rb"[0-9a-fA-F]{64}", s) and hmac.compare_digest(s.lower(), expected) for s in sigs)
Terra's docs don't spell out an age limit. The examples leave the timestamp check off by default, because Hookdeck retries and replays (and Terra's own retries) resend the original t, so a fixed window would reject legitimate redeliveries. Set TERRA_WEBHOOK_TOLERANCE_SECONDS to a positive number to opt in (t is Unix seconds). Upsert records on Terra's record keys (metadata.summary_id, metadata.start_time) instead. Don't dedupe on terra-reference alone: every chunk of a large historical request shares it.
For complete handlers with tests, see examples/express/, examples/nextjs/, examples/fastapi/.
Common Event Types
Dispatch on the body's type field. The examples handle the common types and log the rest.
Event (type) |
Description |
|---|---|
auth |
A user connected a device or provider (status says whether it succeeded) |
deauth |
A user disconnected |
user_reauth |
A user re-authenticated; the user ID may have changed |
access_revoked |
The user revoked access at the provider |
connection_error |
A provider connection failed |
activity |
Normalised workout data |
sleep |
Normalised sleep data |
body |
Body metrics (weight, heart rate, glucose, ...) |
daily |
Daily summary |
athlete |
Profile data |
Others include auth_cancelled, permission_change, google_no_datasource, large_request_sending, large_request_processing, rate_limit_hit, the data types hormone, menstruation, nutrition and clinical_record, lab_report.completed, lab_report.failed and a periodic healthcheck. processing is only an HTTP response and never arrives as a webhook. In ping mode a data delivery carries "type": "s3_payload" and a download URL instead of the data. See references/overview.md.
For the full event reference, see [Terra's event types](https://docs.tryterra.co/reference/health-and-f
Install terra-api-webhooks in Claude Code & Claude Desktop
Sign up to install this skill
Create a free account to reveal the install command and save the skill to your library.
- Reveal the one-line install command
- Save skills to your synced library
- Get notified when skills update
Allowed tools
Tools this skill is permitted to call.
No restriction — this skill can use any tool.
Bundled files
FAQ
What does the terra-api-webhooks skill do?
Receive and verify Terra API webhooks (tryterra.co wearables and health data). Use when setting up a Terra webhook destination, debugging X-Terra-Signature (terra-signature) verification, or handling events like auth, deauth, user_reauth, access_revoked, connection_error, activity, sleep, body and daily.
How do I install the terra-api-webhooks skill?
Copy the skill folder into ~/.claude/skills (the Claude Code tab above does this in one command), or install it as a plugin.
Does the terra-api-webhooks skill run scripts?
Yes, this skill bundles executable scripts. Review the source before installing.
Related skills
skill-creator
Create new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an…
by Anthropicdiscernment-nudge
After you give a substantive answer or draft that the user may act on — advice or recommendations, drafted artifacts such as goals, plans, pitches, proposals…
by Anthropicdata-consolidate
Joins the plant's scheduled exports and connector data into one working dataset — ERP items (NetSuite or Infor M3), sales orders, production work orders…
by Anthropicinspection-to-capa
Runs the quality chain end to end: writes the nonconformance against the requirement it violates, searches history at the moment of writing to say whether…
by Anthropic