Conversion API
The endpoint that receives sales – for server-side and custom integrations, with parameters, responses and limits.
Every sale from track.js ends up at the same endpoint. If you build the integration yourself – e.g. from your own backend once payment has gone through – you can call it directly.
POST https://app.affilyflow.com/api/track/conversion
GET https://app.affilyflow.com/api/track/conversion- Both
GETandPOSTwork.OPTIONSanswers CORS preflight requests. - CORS is open (
Access-Control-Allow-Origin: *), so the endpoint can be called from any browser. - No key is required. What ties the sale to an affiliate is the click ID – or a personal discount code.
The click ID first
Without the click ID the sale can't be attributed to anyone. It arrives from the affiliate link as ?afid= on your site, and track.js stores it in the af_click cookie on your domain. Your server can therefore read the cookie from the customer's request when the order is created and send it along.
If you don't have track.js on the site, store afid from the URL yourself. Only accept values that look like ours: c_ followed by 4–64 characters (letters, digits, _ and -).
Parameters
| Parameter | Alias | Required | Meaning |
|---|---|---|---|
afid | click_id | Yes, when there is a click | The click ID (c_…). Without a click, a personal discount code in coupon/coupons can attribute the sale. |
store | – | Recommended | Your store ID (the same as data-store). Must match the click's store, otherwise store_mismatch. |
order | order_id | Recommended | The order number. The same number is never counted twice in the same program. At most 120 characters. |
total | order_total | Yes | The amount commission is calculated on: goods after discount, excluding VAT and shipping. A machine number (1249.5). |
currency | – | No | ISO 4217 currency code, e.g. DKK or EUR. Without it, the store's settlement currency is used. |
coupon | – | No | The customer's discount code(s) as text, separated by commas (e.g. ANNA10,SUMMER). In a JSON body you can also send coupons as a list. |
Legacy direct links without a click ID can send aff (or aff_id) – the affiliate's tracking ID – together with store instead. The affiliate must then have joined the store's program, otherwise the response is not_joined.
GET
Parameters in the URL. This is what track.js uses as a fallback when the browser has no sendBeacon.
curl "https://app.affilyflow.com/api/track/conversion?afid=c_AbC123xYz_-9&store=DIN_BUTIK&order=1008&total=499¤cy=DKK"POST
Send the fields as JSON in the body. The fields can also be in the URL – if a field is in both, the body wins. This is how track.js sends with navigator.sendBeacon: a POST with the fields in the URL and no body.
curl -X POST https://app.affilyflow.com/api/track/conversion \
-H "Content-Type: application/json" \
-d '{"afid":"c_AbC123xYz_-9","store":"DIN_BUTIK","order":"1008","total":499,"currency":"DKK"}'await fetch('https://app.affilyflow.com/api/track/conversion', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
afid: order.afClick, // saved from the af_click cookie
store: 'DIN_BUTIK',
order: order.number,
total: order.subtotalExVat, // goods after discount, excl. VAT and shipping
currency: order.currency
})
});The body may be at most 64 KB.
Optional body fields
| Field | Meaning |
|---|---|
items | Item lines: a list of { title, variant, qty, price, product_id }. title is required per line. At most 50 lines; long text is truncated. |
subtotal, tax, shipping | The order breakdown (numbers, 0 or above). See below. |
buyer_hash | Fingerprint of the buyer's email: hex(sha256(lowercase(trim(email)))) – 64 hex characters. If it matches the affiliate's email, the sale is recorded as rejected (self_referral). The email itself is never sent. |
coupons | The customer's discount codes as a list of strings, e.g. ["ANNA10"]. See Personal discount codes. |
source | Where the sale comes from. Send "server" when your own server reports the sale. |
The breakdown: if you send total as the order's full amount and include subtotal, commission is calculated on subtotal instead – but never on more than total:
- If
taxis 0 or missing, orsubtotal + shipping + tax = total(VAT added on top), the base issubtotal. - If
subtotal + shipping = total(VAT included in prices), the base issubtotal × (total − tax) / total. - Otherwise the cautious
min(subtotal, total − tax − shipping)is used.
The simplest is to send total as the goods amount excluding VAT and shipping and leave out the breakdown.
For the Google Analytics route, track.js also sends src=ga4 and the event's raw figures – gv (value), gs (shipping), gi (item lines' sum) and gt (tax) – so the server can recalculate the amount with the store's setting. Don't send them yourself; only sales marked src=ga4 are recalculated.
Reporting from your server
Report the sale from your backend once the order is paid:
- At checkout – while it is the customer's own browser calling you – save the value of the
af_clickcookie on the order. - When the order is paid – e.g. in the payment callback or webhook – report the order to the store API with a key.
The browser report (the script or the sale line) can stay as a backup: the same order number only counts once, and when the server reports the same order with the key, the sale shows as Confirmed by server. The store dashboard's Setup and Server-side tracking have ready-made snippets for Laravel, PHP, Node.js and Next.js.
If your server already posts to this endpoint with source: "server", it keeps working as before. If you also send the key in Authorization: Bearer afs_…, the sale is marked as confirmed too – but only the new API has idempotency, order time, refunds and status.
Personal discount codes
A personal discount code is a code the store has assigned to one affiliate under Program → Discount codes in the store dashboard. Send the customer's codes in coupon (text) or coupons (list):
- Valid click: the click decides the sale, as always. A valid click always wins over a code.
- No click, or the click has expired or is unknown: if one of the codes is personal, the sale is attributed to the affiliate the code belongs to.
storemust be included. - No personal code: nothing is recorded, and the response is
no_coupon. A general code for all affiliates earns no commission on its own.
Codes are compared without spaces and in upper case. At most 10 codes per sale are used. Commission for a sale via a code is the program's current rate – there is no click to lock it on. All other guards apply as for a click.
curl -X POST https://app.affilyflow.com/api/track/conversion \
-H "Content-Type: application/json" \
-d '{"source":"server","store":"DIN_BUTIK","order":"1008","total":499,"currency":"DKK","coupons":["ANNA10"]}'Responses
The response is always JSON with a status. What each status means and what to do is in Status codes.
| HTTP | Body | When |
|---|---|---|
| 200 | { "status": "ok" } | The sale is recorded. |
| 200 | { "status": "duplicate" }, "expired" etc. | The request was processed, but the sale earned no commission. |
| 200 | { "status": "no_coupon" } | No valid click, and none of the codes is a personal code. Nothing is recorded. |
| 404 | { "status": "unknown" } | The click ID doesn't exist. |
| 400 | { "status": "error", "reason": "…" } | Neither afid, aff + store nor a discount code + store was included. |
| 413 | { "status": "too_large" } | The body was over 64 KB. |
| 429 | { "status": "rate_limited" } | Too many calls from the same IP address. |
| 500 | { "status": "error" } | Recording failed. Try again. |
A recorded sale awaits the store's approval. Commission is only credited once the sale is approved.
Duplicates and order numbers
- The same order number in the same program is never counted twice – the second call responds
duplicate. It is therefore safe to resend when in doubt. - Without an order number there is no duplicate check on the server. Always send the order number.
- An unfilled placeholder (
DIN_ORDRE_ID,ORDER_ID,{{ … }},[ … ],< … >,% … %etc.) is treated as no order number, so it never takes up the number for every later sale.
Currency
The sale can be in any currency with a rate from the European Central Bank. It is converted to the store's settlement currency before commission and fee are calculated, and the rate is locked on the sale. A currency code that isn't three letters, or a currency without a rate from the last 10 days, is rejected as unsupported_currency.
Limits
- The endpoint is rate limited per IP address. The limit doesn't affect a store's own server in normal use; the response is
429withrate_limitedif it is reached. - Each program has an amount cap per order (50,000 in the settlement currency by default). An order above the cap is rejected as
value_too_high– typically an amount sent in cents. - Long values are truncated rather than rejected: click ID 64 characters, store and order number 120 characters.
Refunds
The open endpoint only reports sales. Refunds – full and partial – are reported with the store API with a key. The WooCommerce plugin and the Stripe webhook report refunds on their own, and the store can always reject a sale under Sales in the dashboard within the program's approval period – see Approval and refunds.
The store API (with a key)
For your own server. The calls are authenticated with the store's API key, so a sale from here shows as Confirmed by server to you and to Affilyflow – it cannot have been sent from a browser. All the rules for a sale (cookie period, maximum order value, blocked affiliates, program rules, self-referral, currency, duplicates and personal discount codes) are the same as for the open endpoint.
GET https://app.affilyflow.com/api/v1/store/ping
POST https://app.affilyflow.com/api/v1/store/conversions
GET https://app.affilyflow.com/api/v1/store/conversions/{order}
POST https://app.affilyflow.com/api/v1/store/conversions/{order}/refundsThe key
- Create a key under Settings → API keys in the store dashboard. It is shown once; we only store a fingerprint of it. A store can have up to 5 active keys, and a key can be revoked at any time.
- Send it in
Authorization: Bearer afs_…(orX-Api-Key: afs_…). The key decides the store –storeis not sent. - The key belongs on your server only. The endpoints have no CORS, so a browser cannot call them. Keep it in an environment variable such as
AFFILYFLOW_API_KEY, never in code or in git.
curl https://app.affilyflow.com/api/v1/store/ping \
-H "Authorization: Bearer $AFFILYFLOW_API_KEY"The answer is the store and the key: { "ok": true, "store": { "slug": "…", "name": "…", "billing_currency": "DKK" }, "key": { "name": "…", "prefix": "afs_…" } }.
Report a sale
curl -X POST https://app.affilyflow.com/api/v1/store/conversions \
-H "Authorization: Bearer $AFFILYFLOW_API_KEY" \
-H "Idempotency-Key: 1008" \
-H "Content-Type: application/json" \
-d '{"order":"1008","total":499,"currency":"DKK","afid":"c_AbC123xYz_-9","order_time":"2026-10-21T14:03:00Z"}'| Field | Required | Meaning |
|---|---|---|
order | Yes | The order number, at most 120 characters. The same number is never counted twice in the same program. An unfilled placeholder is rejected. |
total | Yes | The amount commission is calculated from: the goods after discount, excluding VAT and shipping. A number or a machine number as text ("1249.50") – "1.249,00" is rejected with invalid_total instead of becoming 0. |
currency | Yes | ISO 4217 currency code, e.g. DKK, EUR or SEK. |
afid | When there is a click | The click ID (c_…). Alias: click_id. |
coupons | No | The customer's discount codes as a list (or coupon as text). Without a valid click, a personal discount code attributes the sale. |
order_total | No | What the customer paid (with VAT and shipping). It is then stored as the order's amount, and total is the base. total cannot be larger. |
order_time | Recommended | When the order was placed (ISO 8601). The cookie period is measured from it instead of from the time of the call, so a sale reported later does not fall out of the period. At most 90 days old and not in the future, and the click must have happened before the order. |
buyer_hash | Recommended | hex(sha256(lowercase(trim(email)))). Used only to reject self-referrals. |
items | No | Line items: { title, variant, qty, price, product_id }, at most 50. |
test | No | true = a test sale, see Test mode. |
The body may be at most 64 KB.
Responses:
| HTTP | status | When |
|---|---|---|
| 201 | ok | The sale is recorded and confirmed. |
| 201 | self_referral, rule_breach | The sale is recorded but rejected with a reason (self-referral or a certain rule breach). |
| 200 | confirmed | The browser had already reported the order – now it is confirmed by your server. |
| 200 | duplicate | The order is already reported and confirmed. |
| 422 | expired, unknown, no_coupon, click_after_order, store_mismatch, not_joined, value_too_high, unsupported_currency, blocked, … | The sale earned no commission and is not recorded. See Status codes. |
A 200 or 201 response includes the sale as GET shows it:
{
"status": "ok",
"recorded": true,
"confirmed_by_server": true,
"test": false,
"conversion": {
"order": "1008", "status": "pending", "currency": "DKK",
"order_value": 499, "commission_base": 499, "commission": 62.38, "network_fee": 15.6,
"approval_due_at": "2026-11-20T14:03:12Z", "attribution": "click",
"confirmed_by_server": true, "refunds": []
}
}Idempotency
Send Idempotency-Key with every POST – the order number is a good choice. The same key and the same body within 24 hours returns exactly the same response again (with the header Idempotent-Replayed: true) and records nothing new. Retrying after a timeout is therefore safe.
- The same key with a different body is rejected with
422 idempotency_key_reused. - If a call with the same key is still running, the answer is
409 idempotency_in_progress– retry in a moment. - A
5xxresponse is not stored, so a new attempt with the same key runs again. - Without
Idempotency-Key, the order number still protects against double sales (duplicate).
Retry on network errors, 429 and 5xx – with the same Idempotency-Key and with pauses in between (e.g. 1, 2 and 4 seconds). Don't retry on 4xx: the answer will be the same.
Test mode
With "test": true a test sale is recorded on the store's test link – even without a click. It shows with a test badge in the dashboard, costs nothing, is never paid out and is not counted anywhere. The click ID and discount codes are ignored, and the order number is stored separately, so a test order number never takes up a real one. Look the test sale up with GET …/conversions/{order}?test=true, and refund it with "test": true in the body.
The real test flow – the test link, a purchase and the sale from your server with the test click's afid – works too and shows the whole chain in the live test in Setup.
Look up a sale
curl https://app.affilyflow.com/api/v1/store/conversions/1008 \
-H "Authorization: Bearer $AFFILYFLOW_API_KEY"The answer is { "conversion": { … } } with the status (pending, approved, paid or rejected), the rejection reason, the amounts in the settlement currency, the original amount and rate for another currency, when the approval period ends, whether the sale is confirmed by server, and every refund. An unknown order number gives 404 not_found. URL-encode the order number if it contains /, # or spaces.
Refunds from your server
curl -X POST https://app.affilyflow.com/api/v1/store/conversions/1008/refunds \
-H "Authorization: Bearer $AFFILYFLOW_API_KEY" \
-H "Content-Type: application/json" \
-d '{"reason":"Order cancelled"}'curl -X POST https://app.affilyflow.com/api/v1/store/conversions/1008/refunds \
-H "Authorization: Bearer $AFFILYFLOW_API_KEY" \
-H "Content-Type: application/json" \
-d '{"refund_id":"R-55","amount":150,"total":623.75,"currency":"DKK"}'| Field | Meaning |
|---|---|
amount | The refunded amount. Leave it out to reject the whole sale, as when the store rejects it in the dashboard. |
total | The order total on the same basis as amount (e.g. both with VAT), so the share is amount / total. Without it, the share is taken of the sale's amount. |
base | The refunded part of the commission base (goods without VAT and shipping), when you know it. The reduction is then exact. |
currency | The refund's currency. Without it, the sale's own currency is used; another currency is converted with the sale's locked rate. |
refund_id | Your ID for the refund. The same ID is only counted once (already_applied). Always send it for partial refunds. |
reason | The reason the affiliate and the store see. At most 300 characters. |
test | true to refund a test sale. |
A partial refund reduces commission and fee proportionally; when the refunds cover the whole order, the sale is rejected. A fixed amount per sale is not changed by a partial refund, and leads can only be rejected in full. The rules are the same as in Approval and refunds. The answer is 200 with status (ok, already_applied or already_rejected), full and the sale after the refund; an unknown order number gives 404 not_found.
Errors
All errors have the same shape, and code is what your code should react to (the message is in English and may change):
{ "error": { "code": "invalid_total", "message": "\"total\" must be a number of 0 or more with a decimal point, e.g. 1249.50." } }| HTTP | code | When |
|---|---|---|
| 400 | invalid_json, missing_order, invalid_order, missing_total, invalid_total, missing_currency, invalid_currency, invalid_click_id, invalid_buyer_hash, invalid_order_time, invalid_amount, invalid_idempotency_key | The call is malformed. Fix it – a retry gives the same answer. |
| 401 | missing_key, invalid_key | No key, or the key is invalid or revoked. |
| 404 | not_found | No sale with that order number in your store. |
| 409 | idempotency_in_progress | A call with the same Idempotency-Key is still running. |
| 413 | too_large | The body was over 64 KB. |
| 422 | The sale's status, idempotency_key_reused | The call was well-formed, but the sale or refund didn't go through. |
| 429 | rate_limited | Too many calls with the key. Wait the number of seconds Retry-After says. |
| 500 | server_error | An error on our side. Retry with the same Idempotency-Key. |
| 503 | not_ready, unavailable | The API is temporarily unavailable. Retry after Retry-After. |
See also Custom-built store and Testing and troubleshooting.
Missing something?
Write to us – we answer quickly, and the page gets fixed.