Updated 1 week ago Build

Sahha x Firebase Integration

Learn how to stream health data from Sahha to Firebase Firestore using Cloud Functions and Webhooks. A step-by-step TypeScript guide with code examples.

In this guide you will stream health data from Sahha to Firebase Firestore using Sahha Webhooks and Firebase Cloud Functions (TypeScript) — choosing which data types to send, verifying webhooks securely, and persisting structured events in Firestore.

Sahha SDK / Demo App → Sahha Platform → Webhooks → Firebase Functions → Firestore

Prerequisites

Before you begin, make sure you have:

  • Node.js 18+ installed
  • A Firebase project created
  • Firestore enabled in your Firebase project
  • Firebase CLI installed: npm i -g firebase-tools
  • Access to Data Delivery → Webhooks in the Sahha dashboard
Cloud Functions require the Firebase Blaze (pay-as-you-go) plan. If you’re on the free Spark plan, upgrade to Blaze before deploying functions.

Get data flowing into Sahha Required

Webhooks only fire when Sahha is actually receiving data. Choose how to connect:

Use the Sahha Demo App (fastest way to test)

  1. In the Sahha dashboard, go to Configure → Demo App
  2. Copy the Configuration URL (or scan the QR code)
  3. Install the Sahha Demo App from the App Store / Google Play
  4. In the demo app, paste the Configuration URL (or scan the QR) to connect it to your project
  5. Keep the demo app running so it can collect and submit device data

Once connected, you should see a new profile appear in your Sahha project and data beginning to flow.

If you’ve already integrated the Sahha SDK into your application, ensure that:

  • Your app is successfully streaming data to Sahha
  • You are setting a stable externalId when creating Sahha profiles (for example, your Firebase Auth UID)

This externalId will later be sent back in webhooks as X-External-Id, which allows you to map Sahha events to the correct user in Firestore.

Set up your Firebase Functions project

Install the Firebase CLI (once per machine)

npm install -g firebase-tools

Authenticate with Firebase

firebase login

This links your local machine to your Google account.

Download the starter project — it includes a Cloud Function with signature verification, Firestore writes, and all project configuration already set up.

Download starter project

After downloading:

  1. Unzip and open the project
  2. Open .firebaserc and replace the placeholder project ID with your real Firebase project ID
  3. Link it to your Firebase project — when prompted, select your project and give it an alias (e.g. default):
firebase use --add
  1. Install dependencies:
cd functions
npm install

From your project root, initialize Firebase:

firebase init

When prompted, select:

  • Functions
  • Firestore
  • Your existing Firebase project
  • TypeScript when prompted
  • Node 18 as your runtime

This creates the configuration needed for firebase deploy to work.

Deploy and connect to Sahha

Store your webhook secret

Sahha signs every webhook request. Your Cloud Function must verify this signature.

  1. In Sahha, go to Data Delivery → Webhooks → Create webhook
  2. Copy the Secret value

Then in your terminal run:

firebase functions:secrets:set SAHHA_WEBHOOK_SECRET

You will be prompted to enter the secret — paste it and press Enter.

Deploy the Cloud Function

firebase deploy --only functions

After deployment, get your Cloud Function URL it should look something like this:

https://us-central1-yourproject.cloudfunctions.net/sahhaWebhook

This is your Destination Webhook URL. You can also find it in Firebase Console → Build → Functions → click sahhaWebhookTrigger URL.

Firebase Console Functions page showing the sahhaWebhook trigger URL

Configure Sahha

Go to Sahha Dashboard → Data Delivery → Webhooks → Create webhook and fill in:

Sahha dashboard Data Delivery Webhooks page

  • Webhook name: Firebase Webhook
  • Destination URL: your Cloud Function URL from above
  • Event subscriptions: choose the data you want to stream (Health Scores, Biomarkers, Archetypes, Raw Data Logs)

Click Create webhook.

Test the webhook

In the Sahha dashboard, find your webhook and click Actions → Test. This sends a real signed test payload to your endpoint.

Sahha webhook list with Actions menu and Test button highlighted

To verify it worked, go to the Firebase Console → FunctionsLogs — you should see a successful invocation.

How data works in Firestore

Events are stored under sahha_events/{eventType}/events/{eventHash} — organized by event type with deduplication built in.

Here’s an example of a biomarker event payload that Sahha sends via webhook:

BiomarkerCreatedIntegrationEvent 200
JSON
{
  "id": "1cb680dd-7e67-553c-9a29-c1bc066f6eb7",
  "type": "activity_low_intensity_duration",
  "unit": "minute",
  "value": "345",
  "version": 1,
  "category": "activity",
  "accountId": "4e9357a7-6275-4b22-b0f8-524962e4c7f7",
  "profileId": "b27fac52-0ae6-49d5-97c4-d720b7d6be16",
  "valueType": "long",
  "externalId": "SahhaInternalTestingProfile",
  "aggregation": "total",
  "endDateTime": "2026-02-11T23:59:59Z",
  "periodicity": "daily",
  "createdAtUtc": "2026-02-11T04:00:22.724731Z",
  "startDateTime": "2026-02-11T00:00:00Z"
}
Sahha sends an X-External-Id header with every webhook. Set this to your Firebase Auth UID when creating Sahha profiles so you can map events back to the correct user in Firestore.

Troubleshooting

Webhook requests aren't reaching Firebase +

Check:

  • You deployed the function to the correct Firebase project
  • You copied the correct Trigger URL from Firebase
  • Your Sahha webhook Destination URL matches that exact URL
401 Invalid signature +

This means your secret in Firebase does not match Sahha.

Fix:

firebase functions:secrets:set SAHHA_WEBHOOK_SECRET
firebase deploy --only functions
No data in Firestore +
  • Confirm Sahha is actually receiving data (Demo App or SDK active)
  • Check Cloud Functions logs in Firebase Console → Functions → Logs

Next steps

You now have a secure, production-ready Sahha webhook endpoint in Firebase with automatic streaming into Firestore