Receive webhooks
Webhooks let your backend react when something changes in tiun — a user gets or loses access to a product, a new user signs up, or a user withdraws consent — without the user being in your app. tiun sends a POST request to a URL you choose, and your server takes it from there: provision access in your own database, send a welcome email, or delete a user's data.
You don't need webhooks to gate content. The SDK's userChange event and the server-side checks already tell you what a user can access right now. Webhooks are for keeping your own systems in sync in the background.
How it works
You add an endpoint in the dashboard — an
https://URL on your server — and pick the events it should receive.When one of those events happens, tiun sends your endpoint a small JSON message with the event type and the IDs involved.
Your server replies with a
2xxstatus, then fetches the current state from the tiun API and acts on it.
The event types and their payloads are listed in Webhook events. Retries, timeouts, and delivery statuses are in Webhook delivery.
1. Add an endpoint
In the dashboard, add an endpoint under API & Webhook → Webhooks: the URL tiun should send events to, for example https://example.com/webhooks/tiun, and the events it should receive. The URL must use https://.
You can add more than one endpoint — for example one per service — and each gets only the events you picked for it. You can change an endpoint's URL or events later, or pause it to stop deliveries for a while without removing it. Events that happen while an endpoint is paused aren't delivered to it, even after you turn it back on.
2. Set up an API key
Your handler confirms each event with a server-to-server call, which needs an API key. If you don't have one yet, create one in the dashboard under API & Webhook → API Keys. Store it in your backend environment variables — never in frontend code.
Use the API key and base URL from the same environment as the endpoint:
Live
https://api.tiun.live
Sandbox
https://api-sandbox.tiun.live
3. Handle the request
Every event has the same envelope: an id, a type, a version, an occurred_at timestamp, and a payload with the IDs involved.
Your handler should:
Reply
2xxquickly. tiun waits up to 15 seconds for a response; anything else — a timeout, a4xx, or a5xx— counts as a failure and is retried. Acknowledge first, then do the slow work.Skip duplicates. The same event can arrive more than once, for example after a retry or a manual resend. Store each
idyou've handled and ignore repeats.Confirm with the API. Fetch the user's current state with the UserInfo API — or, for a repeatable product, the purchase's access by reference ID — and act on that, not on the webhook body.
Because you always read the current state, you don't have to worry about events arriving out of order: whatever the API returns is the truth at that moment.
Full example
An Express handler that acknowledges the event, skips duplicates, and syncs the user from the UserInfo API:
alreadyHandled, markHandled, saveUserAccess, savePurchase, and deleteUserData stand in for your own storage. If syncUser throws after you've already replied, tiun won't retry — log the error and recover from your side, for example by re-syncing the user later.
4. Send a test event
Send a test event to your endpoint from the dashboard. You pick the event type, and the dashboard shows the request tiun sent and your server's response, so you can check your handler without making a real purchase.
Test events carry sample IDs such as user-sample-0001 that don't exist in tiun. Your handler should treat a 404 from the UserInfo API as "nothing to do", as in the example above.
5. Monitor deliveries
The endpoint page shows every delivery with its status, HTTP response, and response time, plus delivery rate and failures over the last 24 hours, 7 days, or month. Open a delivery to see each attempt and the event body.
If your server was down and a delivery failed after all retries, fix the problem and resend that delivery from the dashboard — it sends the real event again with the same id.
Go live
Webhook endpoints, API keys, and user IDs are all environment-specific. When you go live:
Add a live endpoint in the dashboard with the events you need.
Switch your handler to the live base URL (
https://api.tiun.live) and a live API key.Send a test event to the live endpoint to confirm it responds.
See setting up your environment for the full sandbox / live workflow.
Last updated
Was this helpful?

