Unified API Example
A complete Unified API integration: wearable connections, webhook ingestion, multi-device deduplication, a live dashboard, and an AI health assistant.
Terra Basecamp is a health data platform built on the Unified API. Users connect their wearables and the app merges the data into a daily dashboard, with an AI assistant on top. It runs as a single Cloudflare Worker backed by Neon Postgres.
terra examples clone unified-api-web-app my-appWhat it demonstrates
User authentication from a custom UI, with
reference_idlinkingWebhook ingestion with signature verification and deduplication
Authentication events: auth, deauth, reauth, and permission changes
Historical backfill of 30 days when a device connects
Multi-device deduplication by provider priority
Reconciliation every 6 hours via cron
An AI assistant built on Terra's MCP tools

Run it yourself
Deploy
npm run setup provisions a Neon database, a Worker, and an R2 bucket, runs migrations, deploys, and prints your App URL. It asks for your Terra dev-id, API key, and webhook signing secret from the dashboard. Re-running it is idempotent.
Point webhooks at your app
Set your webhook destination URL to https://<your-app-url>/api/terra/webhook.
Develop locally with npm run dev, which uses a separate database branch, and ship with npm run deploy.
How the integration works
The webhook endpoint verifies Terra's signature against the raw body before parsing JSON, then returns 200 immediately and processes asynchronously to stay inside Terra's timeout.
The AI assistant connects to the Terra MCP server exposed per connection and hands those tools to the model alongside its own chart tool, so it can fetch and visualise data in one turn.
Explore the code
The repository ships its own guides:
Ingestion pipeline, archiving, idempotency
Connection lifecycle and the reconciliation cron
Provider priority and deduplication
Chat architecture, MCP tools, inline charting
Provisioning and deployment
Last updated
Was this helpful?