Subscription save
Code · Template: Subscription save agent · Runs on http://localhost:3012
A mock subscription store. Ask the agent to cancel as a test subscriber, watch the outcome arrive at the store’s webhook, then confirm the cancellation from the store desk.

| The store desk | Subscribers |
|---|---|
![]() | ![]() |
What it shows
- Receiving a workflow’s webhook.
subscription-save-outcomeposts each outcome to the app. The request isn’t signed, so the receiver checks a secret key in the URL, and saves each outcome once even if Loops retries. - A store applying the outcome. An outcome of
cancelleddoesn’t cancel anything. The store desk confirms it by triggeringsubscription-cancelled, which records it and can send a win-back SMS. - Telling the agent the plan. The agent can’t read the store, so the first message of each thread says which subscription the person has.
The endpoints it uses
| Endpoint | Used for |
|---|---|
POST /chat on subscription-save | Sending one message and getting the reply. |
POST / on subscription-cancelled | Confirming a cancellation from the store desk. |
GET /users | The subscriber list, 50 at a time with Load more. |
GET /users/:userId | A subscriber’s last cancel request, cancellation and memory. |
Run it
- Deploy the Subscription save agent template and tick the optional
subscription-cancelledworkflow. - Copy the organization id, the
subscription-saveloop id and thesubscription-cancelledloop id. - In Settings → API tokens, create a token for the whole organization with access set to Run and read.
- Copy
apps/subscription-save/.env.exampleto.envand fill inLOOPS_API_URL,LOOPS_ORGANIZATION_ID,LOOPS_AGENT_LOOP_ID,LOOPS_CANCELLED_LOOP_IDandLOOPS_API_TOKEN. SetSUBSCRIPTION_WEBHOOK_KEYto a long random string. - On
subscription-save-outcome, setSUBSCRIPTION_WEBHOOK_URLunder Variables and secrets tohttp://localhost:3012/api/subscription-outcome?key=<your key>, and add the app’s host to its allowed hosts. - Run
bun run dev --filter=subscription-save.
If Loops doesn’t run on your machine, the webhook URL has to be one it can reach, for example through a tunnel. Set RESTART_URL on subscription-cancelled to put a link in the win-back SMS.
Where to look in the code
| File | What it does |
|---|---|
src/lib/loops.ts | Server functions for the Loops endpoints. |
src/lib/subscribers.ts | What Loops doesn’t store: subscribers, their plans, threads and chats. |
src/routes/api/subscription-outcome.ts | The webhook receiver. |
src/lib/outcomes.server.ts | Every outcome received, kept in .data/outcomes.json. |
src/routes/customers.$customerId.tsx | A subscriber’s cancel chat and what Loops knows about them. |
src/routes/desk.tsx | The store desk: outcomes to apply, and cancellations to confirm. |
Last updated on

