Docs
Server-side integration
Report signups, one-time and recurring sales, refunds and disputes from your own server, for form-post and guest checkouts.
Use this when your checkout runs on your server, when buyers check out as guests, or when you would rather report payments from your own billing code than point a webhook at Affiligato. Everything goes through the Conversions API with a secret key from Integrations → Conversions API.
Read the partner code
The tracking script keeps the referral in the aff_ref cookie on your own domain as code.clickId. On your server, read that cookie and split it at the first .: the part before is the partner code, the part after is the click. Codes are eight characters of a–k, m–n, p–z and 2–9; ignore anything else.
const [code, clickId] = decodeURIComponent(cookies.aff_ref ?? '').split('.')
if (!/^[a-km-np-z2-9]{8}$/.test(code ?? '')) return // no referral
Report the signup
When the buyer becomes your customer, at account creation or at a guest’s first purchase:
POST https://app.affiligato.com/api/v1/signups
Authorization: Bearer afk_…
{ "code": "k7m2pq9x", "click_id": "0b5c…", "email": "buyer@example.com", "customer_id": "cus_123" }
Send customer_id when you have one: later payments match it exactly. A guest checkout without an account can send the email alone. Send click_id too, so the signup keeps the partner’s sub-ID and counts toward that click’s conversion. The first partner to refer a customer keeps them, unless your program pays the last click and the signup brings another partner’s click. Every answer is listed in the API reference: only a 5xx is worth sending again.
Report each payment
POST https://app.affiligato.com/api/v1/sales
Authorization: Bearer afk_…
{ "id": "pi_3P…", "amount": 4900, "currency": "usd", "customer_id": "cus_123", "product_id": "lifetime" }
Use one id per payment, the one your billing gives it: a Stripe payment intent for a one-time payment, an invoice id for each subscription renewal. Sending the same id twice never pays twice. Add "interval": "year" for a yearly plan so rules that pay yearly plans in parts can match, and "code" when the payment arrives with a code but no signup.
Report money back
A refund, in full or in part, and a dispute the customer won:
POST https://app.affiligato.com/api/v1/refunds
Authorization: Bearer afk_…
{ "id": "pi_3P…", "amount": 2500, "refund_id": "re_1" }
id is the sale’s id. Leave out amount for a full refund, and give each refund its own refund_id (a lost dispute can use the dispute’s id), so a retried call counts once. The total taken back never exceeds the sale.