Affiliate track
id: core-affiliate-track owner: core method: POST path: /wp-json/headlesswp/v1/affiliate/track title: Affiliate track usedBySite: true
POST /wp-json/headlesswp/v1/affiliate/track
Sets AffiliateWP-compatible tracking cookies from the headless client and records an AffiliateWP visit when AffiliateWP is active.
Auth + CSRF
- Auth: public
- Proxy nonce required: yes (via
/api/secure/**) - CSRF: proxy-enforced
X-WP-Noncefor POST requests.
Request schema
JSON body fields:
ref(required, string | int): affiliate ID. Must resolve to a positive integer after normalization.campaign(optional, string): campaign slug up to 128 characters. Empty/whitespace-only strings are treated as not provided.landingUrl(optional, string | null): absolutehttp(s)URL for the landing page.referrer(optional, string | null): absolutehttp(s)URL for document referrer.
Notes:
- Unknown fields are rejected with
VALIDATION_FAILEDandfieldErrors. refis normalized by stripping non-digits and leading zeros before validation.
Response schema
Success envelope:
{
"data": {
"ref": "123",
"campaign": null,
"ttlSeconds": 2592000,
"expiresAt": "2026-01-03T07:48:01+00:00",
"flags": {
"domain": "",
"path": "/",
"secure": true,
"httpOnly": true,
"sameSite": "Lax"
}
},
"meta": {
"correlationId": "abc123",
"visitRecorded": true,
"visitId": 987
}
}
campaignisnullwhen not provided.ttlSecondsreflects the resolved cookie TTL (AffiliateWP settings or fallback).flagsecho the configured cookie attributes.meta.visitRecordedistruewhen an AffiliateWP visit row was created.meta.visitIdis the created visit ID, otherwisenull.- Cookies emitted by this route include
affwp_ref, optionalaffwp_campaign, andaffwp_ref_visit_id(visit-link cookie used by AffiliateWP to attach checkout referrals back to the originating visit so conversion state flips fromfalsetotrue).
Error codes
UNSUPPORTED_MEDIA_TYPE(415) — Content-Type must beapplication/json.VALIDATION_FAILED(422) — validation failed (seefieldErrors).RATE_LIMITED(429) — rate limit exceeded (details.bucket = "affiliate_track").