Upmind API - Affiliate Cookie Flow
Integrate affiliate tracking with Upmind.
Last updated 2 months ago
Affiliate link and referral cookie flow
This guide explains how to integrate affiliate tracking with Upmind when building a custom client area. It covers:
Affiliate link visits
Referral signups
Referral orders
The same flow applies whether you use Upmind’s first-party affiliate system, Post Affiliate Pro integration, or both.
Core concept
referral_cookie is an opaque, encrypted string used by the affiliate abstraction layer. Your frontend should:
Send it when available
Store any updated value returned by the API
Re-send it on registration and order conversion requests
Do not attempt to parse, modify, or en/decode referral_cookie; treat it as a transport value.
Post Affiliate Pro
When PAP is configured in your Brand’s settings, the click data will be sent to PAP’s tracking URL, and the referral_cookie will contain the visitorId, which PAP uses to correlate link clicks with conversions. Typically, PAP affiliate links can be identified by the presence of an affiliate ID in the query string, e.g. ?aid=abc123.
End-to-end flow
The visitor lands on an affiliate URL.
Frontend calls
POST /api/affiliate_link/visitwith visit metadata and existingreferral_cookie(if present).API responds with
redirect_urland optionally a refreshedreferral_cookie(+ max age).Frontend sets/updates the browser cookie and redirects the visitor.
When the visitor registers (e.g.
/api/clients/register), sendreferral_cookie.When converting basket to invoice (
/api/orders/<order_id>/convert), sendreferral_cookieagain.
This ensures referral attribution can be linked from click > signup > paid order.
API 1: Track affiliate link visit
Endpoint:
POST https://api.upmind.io/api/affiliate_link/visit
Remember to include your Upmind domain in the Origin header so we can determine the correct brand + settings context.
Example: Origin: https://xyz.upmind.app
Request body fields:
visit_url(required): Full current browser URL, including query string and hash.To configure the onward redirect for Post Affiliate Pro links, it’s possible to add a &redirect=
parameter to affiliate links; ensure this is included in
visit_urlfor this to be returned asredirect_urlin the response. As long as the redirect URL is on the same domain as the visit URL or is added in your Upmind brand’s domain settings, it will be permitted as a redirect target; otherwise, your configured default redirect URL will be used; this is a security measure to prevent malicious redirects.
referrer_url(required): Browser referrer URL.user_agent(required): Browser user agent string.referral_cookie(optional): Existing referral cookie value, if already present.
Example request:
Example{
"visit_url": "https://example.com/?aid=abc123&utm_source=partner&redirect=https%3A%2F%2Fexample.com%2Fproducts",
"referrer_url": "https://partner.example.net/review-page",
"user_agent": "Mozilla/5.0 (...) Safari/537.36",
"referral_cookie": "<existing-cookie-if-any>"
}Example success payload:
Example{
"data": {
"redirect_url": "https://example.com/products",
"referral_cookie": "<new-or-updated-cookie>",
"referral_cookie_max_age": 2592000
}
}Client handling rules:
If
data.referral_cookieexists, set/update a first-party cookie in the browser.Use
data.referral_cookie_max_ageas the cookie lifetime when present.Redirect the visitor to
data.redirect_url.
API 2: Send referral cookie during client registration
Supported registration endpoints:
POST /api/clients/register- Standard client registration endpointPOST /api/clients/register/guest- Guest client creation endpoint for basket operationsPOST /api/clients/<client_id>/complete_registration- Guest registration completion endpoint
Payload field:
referral_cookie(optional): Pass the current cookie value from the browser.
Example standard registration payload excerpt:
Example{
"email": "customer@example.com",
"firstname": "Alex",
"lastname": "Doe",
"password": "<redacted>",
"referral_cookie": "<cookie-from-visit-step>",
"user_agent": "Mozilla/5.0 (...) Safari/537.36"
}API 3: Send referral cookie when converting basket to order invoice
Endpoint:
PATCH /api/orders/<order_id>/convert
Payload field:
referral_cookie(optional): Pass the current cookie value so the order referral can be associated.
Example request:
Example{
"payment_details_id": 12345,
"referral_cookie": "<cookie-from-visit-step>"
}Why this matters:
The referral cookie is stored against the initial order invoice and later used to record the affiliate sale after payment is made.
Recommended integration pattern (Frontend)
On every page load where affiliate params may be present, call
/api/affiliate_link/visit.Always include the current cookie value in that call when available.
Persist returned cookie as a first-party cookie.
Include cookie value in:
/api/clients/registeror/api/clients/register/guestor/api/clients/<client_id>/complete_registration/api/orders/<order_id>/convert
Do not attempt to modify cookie contents in frontend code.
Implementation checklist
Capture and send
visit_url,referrer_url,user_agenton link visitPersist returned
referral_cookiePass
referral_cookieduring registrationPass
referral_cookieduring basket conversionAllow graceful behavior if the cookie is absent