Conversion API

The endpoint that receives sales – for server-side and custom integrations, with parameters, responses and limits.

View as Markdown

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.

EndpointHTTP
POST https://app.affilyflow.com/api/track/conversion
GET  https://app.affilyflow.com/api/track/conversion
  • Both GET and POST work. OPTIONS answers 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

ParameterAliasRequiredMeaning
afidclick_idYes, when there is a clickThe click ID (c_…). Without a click, a personal discount code in coupon/coupons can attribute the sale.
store–RecommendedYour store ID (the same as data-store). Must match the click's store, otherwise store_mismatch.
orderorder_idRecommendedThe order number. The same number is never counted twice in the same program. At most 120 characters.
totalorder_totalYesThe amount commission is calculated on: goods after discount, excluding VAT and shipping. A machine number (1249.5).
currency–NoISO 4217 currency code, e.g. DKK or EUR. Without it, the store's settlement currency is used.
coupon–NoThe 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.

GETShell
curl "https://app.affilyflow.com/api/track/conversion?afid=c_AbC123xYz_-9&store=DIN_BUTIK&order=1008&total=499&currency=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.

POST with JSONShell
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"}'
Node · after paymentJavaScript
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

FieldMeaning
itemsItem 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, shippingThe order breakdown (numbers, 0 or above). See below.
buyer_hashFingerprint 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.
couponsThe customer's discount codes as a list of strings, e.g. ["ANNA10"]. See Personal discount codes.
sourceWhere 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 tax is 0 or missing, or subtotal + shipping + tax = total (VAT added on top), the base is subtotal.
  • If subtotal + shipping = total (VAT included in prices), the base is subtotal × (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:

  1. At checkout – while it is the customer's own browser calling you – save the value of the af_click cookie on the order.
  2. 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. store must 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.

POST · personal discount code without a clickShell
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.

HTTPBodyWhen
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 429 with rate_limited if 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.

EndpointsHTTP
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}/refunds

The 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_… (or X-Api-Key: afs_…). The key decides the store – store is 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.
Try the keyShell
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

POST /api/v1/store/conversionsShell
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"}'
FieldRequiredMeaning
orderYesThe order number, at most 120 characters. The same number is never counted twice in the same program. An unfilled placeholder is rejected.
totalYesThe 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.
currencyYesISO 4217 currency code, e.g. DKK, EUR or SEK.
afidWhen there is a clickThe click ID (c_…). Alias: click_id.
couponsNoThe customer's discount codes as a list (or coupon as text). Without a valid click, a personal discount code attributes the sale.
order_totalNoWhat 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_timeRecommendedWhen 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_hashRecommendedhex(sha256(lowercase(trim(email)))). Used only to reject self-referrals.
itemsNoLine items: { title, variant, qty, price, product_id }, at most 50.
testNotrue = a test sale, see Test mode.

The body may be at most 64 KB.

Responses:

HTTPstatusWhen
201okThe sale is recorded and confirmed.
201self_referral, rule_breachThe sale is recorded but rejected with a reason (self-referral or a certain rule breach).
200confirmedThe browser had already reported the order – now it is confirmed by your server.
200duplicateThe order is already reported and confirmed.
422expired, 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:

201JSON
{
  "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 5xx response 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

GET /api/v1/store/conversions/{order}Shell
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

Full refundShell
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"}'
Partial refundShell
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"}'
FieldMeaning
amountThe refunded amount. Leave it out to reject the whole sale, as when the store rejects it in the dashboard.
totalThe 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.
baseThe refunded part of the commission base (goods without VAT and shipping), when you know it. The reduction is then exact.
currencyThe refund's currency. Without it, the sale's own currency is used; another currency is converted with the sale's locked rate.
refund_idYour ID for the refund. The same ID is only counted once (already_applied). Always send it for partial refunds.
reasonThe reason the affiliate and the store see. At most 300 characters.
testtrue 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):

ErrorJSON
{ "error": { "code": "invalid_total", "message": "\"total\" must be a number of 0 or more with a decimal point, e.g. 1249.50." } }
HTTPcodeWhen
400invalid_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_keyThe call is malformed. Fix it – a retry gives the same answer.
401missing_key, invalid_keyNo key, or the key is invalid or revoked.
404not_foundNo sale with that order number in your store.
409idempotency_in_progressA call with the same Idempotency-Key is still running.
413too_largeThe body was over 64 KB.
422The sale's status, idempotency_key_reusedThe call was well-formed, but the sale or refund didn't go through.
429rate_limitedToo many calls with the key. Wait the number of seconds Retry-After says.
500server_errorAn error on our side. Retry with the same Idempotency-Key.
503not_ready, unavailableThe 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.

Contact support