terra-unified-api

Implements production-tested best practices for Terra API webhook handling, data storage, and connection lifecycle.

Updated Sep 2, 2026
One-click install
npx skills add https://github.com/tryterra/agent-skills --skill terra-unified-api-tryterra
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: terra-unified-api
Source: https://github.com/tryterra/agent-skills/tree/main/skills/terra-unified-api
Command: npx skills add https://github.com/tryterra/agent-skills --skill terra-unified-api-tryterra

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Integrating Terra API correctly is easy to get wrong: unverified webhook signatures accept forged health data, deduplicating on the wrong header silently drops large-request chunks, and plain overwrite upserts erase enrichment scores. This Skill provides 21 prioritized rules distilled from a production multi-device integration so agents and developers avoid these failure modes. ## Core Features & Use Cases - Webhook Handling Rules: Verify terra-signature HMAC over the raw body, acknowledge within the 8-second timeout, deduplicate on X-Terra-Trace-Id, and archive raw payloads to object storage. - Data & Idempotency Rules: Key records by natural identifiers (summary_id, connection+date), apply superset-guarantee overwrites gated on X-Terra-Ordering-Timestamp, and COALESCE enrichment scores so nulls never overwrite. - Auth & Lifecycle Rules: Handle all seven auth event types, swap Terra user IDs on user_reauth, parse comma-separated scopes, and reconcile connection state against the API. - Use Case: When building a webhook endpoint that receives sleep and activity data from Garmin and Oura users, read the webhooks-* and data-* rules to implement signature verification, deduplication, and idempotent upserts with correct/incorrect TypeScript and SQL examples. ## Quick Start Ask your agent to review or implement a Terra API webhook endpoint using the terra-unified-api rules, starting with signature verification and deduplication.

Frequently Asked Questions about terra-unified-api

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I verify Terra API webhook signatures?

Verify the terra-signature or X-Terra-Signature header (read case-insensitively) as an HMAC-SHA256 over the raw, unaltered request body before any JSON parsing. Re-serializing a parsed body breaks verification, so capture raw bytes first and reject invalid signatures with 401.

How do I deduplicate Terra API webhook deliveries?

Deduplicate on the X-Terra-Trace-Id header, which uniquely identifies each delivery and stays stable across retries. Do not dedupe on terra-reference, since every chunk of a large request shares it and later chunks would be silently dropped.

Why do my Terra API enrichment scores disappear after re-delivery?

data_enrichment scores do not follow the superset guarantee, so a later webhook can carry null scores for a day that previously had values. Upsert score columns with COALESCE(excluded.col, table.col) so incoming nulls never overwrite stored values.

What happens when a user re-authenticates a wearable with Terra API?

Terra API issues a new Terra user ID and sends a user_reauth event containing both old and new IDs. You must swap the stored ID in place, or future webhooks will not match any known connection and the old connection appears active forever.

How should I store Terra API daily and sleep data in a database?

Key activity and sleep rows by metadata.summary_id, and daily, body, nutrition, and menstruation rows by (connection, date) using the date sliced from the ISO string before timezone conversion. Extract metrics into typed columns and archive raw payloads in object storage linked by a payload_key.

Can I test a Terra API integration without real devices?

Yes. Mock the terra-api SDK, database client, and background-task scheduling at module boundaries, making async processing eager. Use terra events resend from the Terra CLI to replay real stored payloads against your endpoint for realistic coverage.