Skip to content

Webhooks

Webhooks notify your application when an activity, a test or an uploaded file changes in SweatStack. SweatStack sends an HTTP POST to the endpoints you register.

Set up webhooks

Register one or more endpoint URLs on your app's Webhooks tab (open the app from Settings → API). SweatStack sends every event to every registered endpoint.

When you save your first endpoint, SweatStack generates a webhook secret. The secret starts with whsec_. Use it to verify that an event came from SweatStack. To replace the secret, click Roll secret. SweatStack signs every delivery after that with the new secret, so update your receiver at the same time.

Event types

SweatStack sends these events:

Event type Sent when
activity_created An activity was created.
activity_updated An activity was updated.
activity_deleted An activity was deleted.
test_created A test was created.
test_updated A test was updated.
test_deleted A test was deleted.
source_processed An uploaded file was processed into activities.
source_failed An uploaded file failed to process.

Webhook payload

Every event has the same shape:

{
  "id": "01JZ3K6Q8V2YH5T0R9C4M7N1PD",
  "user_id": "string",
  "event_type": "activity_created",
  "resource_id": "string",
  "timestamp": "2026-05-06T12:00:00Z"
}

id is the event's ID. It is the same on every retry of the event, and the webhook-id header carries the same value. Use it to detect duplicates.

resource_id is the ID of the resource the event is about: an activity ID for activity_* events, a test ID for test_* events, a source ID for source_* events.

The payload carries no resource data. When you receive an event, fetch the resource from the matching endpoint.

Delivery latency

There is no latency guarantee. In the typical case, SweatStack sends the event within seconds of the activity reaching it: the source platform usually delivers a new activity within seconds, and SweatStack's own processing adds seconds, not minutes, before the event goes out.

Sometimes the source platform's own sync to SweatStack is much slower, and then the webhook is delayed by the same amount. Build for the typical case of seconds, and handle delayed and out-of-order arrivals as normal, not as errors.

Response time requirement

Your endpoint must return a 2xx status code within 2 seconds to acknowledge an event.

If a delivery times out, cannot connect, or gets a 5xx, SweatStack retries it on a fixed schedule: 8 s, 32 s, 128 s, 512 s, 34 min, 2.3 h, 9.1 h. That is eight attempts over about twelve hours. After the last attempt, SweatStack drops the event for that endpoint. Each endpoint is retried on its own: an endpoint that acknowledged an event never receives it again because another endpoint failed.

A 4xx answer is final, and SweatStack does not retry it, with two exceptions: 408 Request Timeout and 429 Too Many Requests are retried like a timeout. If your endpoint answers 404 or 401, check the URL and your signature verification in your API settings. SweatStack does not redeliver those events.

Verify webhook signatures

SweatStack signs every delivery as the Standard Webhooks specification describes. Every delivery carries three headers:

Header Value
webhook-id The event's id.
webhook-timestamp The time of signing, in Unix seconds.
webhook-signature v1, followed by the base64-encoded HMAC-SHA256 signature.

Every delivery also carries X-Sweatstack-Event, the event type, so you can route an event before you parse the body.

Verify every delivery before you process it. Use a Standard Webhooks library for your language, and pass it your webhook secret as SweatStack shows it, whsec_ included. Give the library the raw request body: if you parse and serialize the JSON again, the signature no longer matches.

from standardwebhooks import Webhook, WebhookVerificationError

webhook = Webhook("whsec_...")


def verify(body: bytes, headers: dict[str, str]) -> dict:
    """Return the event, or raise WebhookVerificationError."""
    return webhook.verify(body, headers)

Install with pip install standardwebhooks. If you use the FastAPI helper, its WebhookPayload dependency verifies these headers for you from version 0.100.0 of the Python library.

import { Webhook } from "standardwebhooks";

const webhook = new Webhook("whsec_...");

// Throws if the signature does not match. `body` is the raw request body.
const event = webhook.verify(body, headers);

Install with npm install standardwebhooks.

import standardwebhooks "github.com/standard-webhooks/standard-webhooks/libraries/go"

webhook, err := standardwebhooks.NewWebhook("whsec_...")
if err != nil {
    log.Fatal(err)
}

// body is the raw request body, r is the *http.Request.
if err := webhook.Verify(body, r.Header); err != nil {
    http.Error(w, "invalid signature", http.StatusBadRequest)
    return
}

The libraries reject a delivery whose webhook-timestamp is more than 5 minutes from your server's clock. This protects you against replayed deliveries.

Verify a signature without a library

If no library exists for your language, verify the signature yourself:

  1. Remove the whsec_ prefix from your webhook secret.
  2. Base64-decode the rest. The result is the signing key.
  3. Build the signed content: {webhook-id}.{webhook-timestamp}.{body}, with the raw request body.
  4. Compute the HMAC-SHA256 of the signed content with the signing key.
  5. Base64-encode the result.
  6. Split webhook-signature on spaces. Each part has the form v1,{signature}.
  7. Compare your result with each signature, using a constant-time comparison. Accept the delivery if one of them matches.
  8. Reject the delivery if webhook-timestamp is more than 5 minutes from your server's clock.

Deprecated: X-Sweatstack-Signature

Deprecated

SweatStack removes the X-Sweatstack-Signature header on 15 February 2027. If your receiver checks it, verify webhook-signature instead before that date.

If your app received webhooks before the Standard Webhooks headers, its deliveries also carry X-Sweatstack-Signature, in the format t={timestamp},v1={signature}: a hex-encoded HMAC-SHA256 over {timestamp}.{body}, keyed by the secret as text. Other apps do not receive it.

Handle duplicate deliveries

SweatStack retries on failure (see Response time requirement). If your endpoint processed an event and then timed out, you receive the event again. A retry has the same id and the same body as the first delivery. If you already processed an event with that id, return a 2xx and do nothing else. Two different events about the same resource have different IDs.

Best practices

  • Verify signatures. Always verify before you process the event.
  • Return fast. Acknowledge with a 2xx within 2 seconds, then process asynchronously.
  • Be idempotent. SweatStack can deliver an event more than once. Store the id of each event you processed, and skip an event whose id you already stored.
  • Log events. Keep a record of received webhooks for debugging and reconciliation.

Patterns and gotchas

Webhooks are app-level, not per-user. An endpoint registered in your API settings receives events for every user of your app. The user_id field on the payload tells you which one.

Payloads carry IDs, not data. An event tells you that something happened. It does not include the activity, test or source itself. To enrich an event with the resource, your handler calls the relevant SweatStack endpoint with that user's access token. So your webhook handler needs a way to look up tokens by user_id, typically a small key-value store or your own user database.

Mobile apps cannot receive webhooks directly. A webhook is an HTTP POST to a public endpoint, and a phone is not one. The standard pattern is a server-side gateway (a small worker or function) that receives the SweatStack webhook, looks up the user's push token, and sends the event on to APNs (iOS) or FCM (Android). The gateway is also the right place to do the enrichment described above. See the native mobile app guide for an end-to-end example.

A deleted resource is gone. On activity_deleted and the other *_deleted events, the resource no longer exists, so fetching it returns 404. Acknowledge the event and remove your copy. Do not fail your handler on that 404, or SweatStack keeps retrying an event you have already handled. A user who deletes all of their activities produces one event per activity, in a burst.

Next steps