Integrations
Webhooks
Horse posts each subscription event to your server as it happens, so you can unlock something server-side, update a CRM, or report to an ad network Horse doesn't talk to.
#Add an endpoint
On the app's Developer → Webhooks tab, add your endpoint's URL (it must be https) and pick the events to send, or leave all of them on. The signing secret is shown once: save it in your server's secrets. Send test posts a TEST event.
#Events
| Event | When |
|---|---|
INITIAL_PURCHASE | A first purchase, including the start of a free trial |
RENEWAL | A subscription renewed |
TRIAL_CONVERTED | A free trial turned into a paid subscription |
NON_RENEWING_PURCHASE | A lifetime unlock, consumable or non-renewing subscription |
PRODUCT_CHANGE | An upgrade, downgrade or crossgrade |
CANCELLATION | Auto-renew turned off. Access lasts until the period ends. |
UNCANCELLATION | Auto-renew turned back on |
BILLING_ISSUE | A renewal payment failed |
GRACE_PERIOD | The subscription entered Apple's billing grace period |
EXPIRATION | Access ended |
REFUND | Apple refunded a purchase |
REFUND_REVERSED | Apple reversed a refund |
TRANSFER | Purchases moved from one customer to another (for example after a restore) |
#The request
POST https://your.server/horse
Content-Type: application/json
User-Agent: Tally-Webhooks/1.0
X-Tally-Event: RENEWAL
X-Tally-Delivery: <delivery id>
X-Tally-Signature: t=1792900000,v1=<hex>{
"id": "…", "type": "RENEWAL", "at": 1792900000000, "createdAt": 1792900000412,
"environment": "Production", "source": "asn",
"app": { "id": "app_…", "bundleId": "com.example.app", "name": "Example" },
"customer": { "id": "…", "appUserId": "…", "aliases": [] },
"productId": "com.example.app.yearly", "entitlementIds": ["pro"], "periodType": "normal",
"originalTransactionId": "…", "transactionId": "…",
"price": { "amount": 39.99, "currency": "USD", "usd": 39.99 },
"meta": {}
}periodTypeistrial,intro,promoornormal.sourcesays who told Horse:asn(Apple's notifications),sdk(the app),admin(the dashboard) orapi.- Sandbox events are sent too, marked
"environment": "Sandbox".
#Check the signature
The signature is an HMAC-SHA256 of <t>.<raw body> with your signing secret, in hex. Compare in constant time, and refuse a t more than a few minutes old:
verify.ts
import { createHmac, timingSafeEqual } from "node:crypto";
export function verify(rawBody: string, header: string, secret: string): boolean {
const { t, v1 } = Object.fromEntries(header.split(",").map((p) => p.split("=")));
if (!t || !v1 || Math.abs(Date.now() / 1000 - Number(t)) > 300) return false;
const expected = createHmac("sha256", secret).update(`${t}.${rawBody}`).digest("hex");
return v1.length === expected.length && timingSafeEqual(Buffer.from(v1), Buffer.from(expected));
}Use the raw body exactly as received. A body that was parsed and serialised again won't match.
#Answer quickly
- Answer with a 2xx status within 4 seconds, and do the work afterwards.
- Anything else, including a 4xx, is retried with growing gaps for about a day (12 tries), then given up. Each delivery's result is on the Webhooks tab.
- An event can arrive more than once. Use its
idto ignore repeats.