sale.created webhook.
Before you start
- An API key for the program you’re reporting into. The key is what tells Referly which program the sale belongs to, so there’s no program ID in the body.
- API access, which is included with the Business plan.
- Something that identifies the affiliate. Usually that’s the click ID you captured in the browser and stored on your user.
Report a sale
The smallest useful request: who converted, how much they paid, and which click brought them in.99.00, not 9900 and not "$99.00" — there’s no currency conversion on this endpoint, so a value in the wrong unit becomes a commission in the wrong unit.
Identify who to credit
Every request has to name the affiliate one way or another. Send one of the following.referralId
The workhorse, and the one to use if you captured a click. Despite the name it accepts four different things, and Referly tries them in this order:1
An existing referred customer's ID
The
id of a referral already in your program. Direct hit, no ambiguity.2
A click ID
A numeric value is looked up as a click. The affiliate behind that click gets the credit, and the click, the customer, and the sale stay joined up in your reports. This is what
window.affiliateId holds.3
An affiliate's ID
Credits that affiliate directly, with no click attached.
4
An affiliate link code
The code from the affiliate’s referral link — the value that travels in the
ref parameter.promoCode
promoCode takes priority. If you send it alongside referralId, the promo code decides the affiliate and the other identifier is ignored.Request fields
A few behaviours worth knowing before you rely on them:
taxandshippingare never subtracted automatically. They only reduce the commission base if the matching setting is turned on in your program. Sending them on a program without those settings records the amounts but changes nothing.commissionRatebypasses the plan entirely. A percentage outside 0–100 is rejected, and a negative flat amount is rejected. Leave it out and the affiliate’s commission plan decides.- Product rules don’t block API sales. If you send a
productthat doesn’t satisfy a product-based rule, the requirement is bypassed rather than the sale being refused.
What happens when the sale lands
In order:- The affiliate is resolved from your identifier. If nothing resolves, no commission is created.
- The referred customer is found or created. A new email under a known affiliate becomes a new referral, and the click you referenced is attached to it, so the click, customer, and sale all line up in your reports.
- Duplicates are filtered out. If a sale already carries the
externalIdorexternalInvoiceIdyou sent, nothing new is written. - The commission base is calculated —
totalEarned, minus tax and shipping where your program deducts them. - The commission plan runs. Rules, conditions, holding periods, and recurring-payment limits are all evaluated, unless you overrode the rate.
- Fraud prevention runs if it’s enabled, which can put the commission on hold instead of approving it.
- The sale and commission are written, along with any multi-level commissions for the affiliate’s own referrer.
- Notifications go out — the
sale.createdwebhook, any postback URL, and the new-sale emails to the affiliate and to you.
The response
A successful call returns the sale that was written:id if you plan to refund or update the sale later.
Recurring payments
Report every renewal as its own sale, with the invoice or charge ID of that particular payment inexternalId or externalInvoiceId. Referly counts payments per customer, so recurring commission plans — “pay for the first 12 months”, “pay on the first 3 payments” — depend on each renewal arriving as a separate call.
Use the click ID you stored at sign-up for every one of them. The visitor’s cookie is long gone by the second renewal; your database is the only thing that still knows who referred them.
Refunds, corrections, and removals
A sale can’t be refunded once it has been paid out, marked as manually paid, pulled into a payout batch, or once its refund window has closed. Those come back
400 with a reason telling you which of those it was.
Errors
Full reference in Errors.
Before you go live
- Send
externalIdon every call, without exception. It’s the difference between a safe retry and a double payout. - Store the click ID at sign-up rather than reading a cookie at payment time.
- Test with a real affiliate link in a private window, then report a small sale and confirm it appears against the right affiliate with the commission you expect.
- If a payment integration already covers this checkout, don’t report it from your server as well.
Related
Idempotency
Retry safely without creating duplicate sales.
Server-side tracking overview
Where the identifier you send comes from.
Create a sale
The endpoint reference, with a request builder.
Webhook event types
What Referly sends back once the sale is recorded.