Skip to content
中文

Exchange a grant code or publishable key

Code Mode: praxis.customer.accessTokens.create

HTTP: POST /customer/v1/access_tokens

Turn a grant code, or a publishable key for an anonymous visitor, into the Praxis customer access token that authorizes the Kit’s sessions and playbacks. It is PRE-AUTH: no platform API key is needed, because the grant code or the publishable key is the credential; the Kit calls it from the browser, so send the page Origin when the code or key is bound to one. Send exactly one of grant_code or publishable_key — the door refuses any other combination with 400. With grant_code the code is consumed atomically: concurrent attempts have exactly one winner, and unknown, already used, expired and foreign codes all answer 401 GRANT_CODE_INVALID. With publishable_key a new anonymous customer (anon_…) is created and merged into the identified one later if it signs in. The sign-in may be bound to an origin at creation; when the request Origin does not satisfy it, the exchange answers 403 ORIGIN_NOT_ALLOWED, and a blocked end user answers 403 CUSTOMER_BLOCKED. The access token lasts at most two hours and never outlives the sign-in; renew it with praxis.customer.accessTokens.renew before expires_at. This door has its own per-IP anonymous budget: over it answers 429 RATE_LIMITED with Retry-After. A publishable key may also carry its own limits (anon_rate_per_min and daily_session_cap, set on the key): over the key’s per-minute exchanges the door answers 429 PUBLISHABLE_KEY_RATE_LIMITED, and once the key has admitted daily_session_cap new anonymous visitors in the current UTC day it answers 429 PUBLISHABLE_KEY_DAILY_CAP_REACHED to a new visitor while a returning visitor with a continuation_token still continues; both carry Retry-After, the seconds until their UTC minute or day ends. A key may also carry a daily_spend_cap, the most its visitors’ usage may cost in one UTC day: once the usage events of this key in the current UTC day add up to it (when the platform has switched the spend cap on for your organization), the door answers 429 PUBLISHABLE_KEY_DAILY_SPEND_CAP_REACHED to every visitor, a returning one with a continuation_token included, with Retry-After until 00:00 UTC.

Signature

praxis.customer.accessTokens.create(args:{headers?:{Origin?:string};body:{/** A grant code (cgc_…) from grant_codes, for an end user you signed in from your backend; it works once. */ grant_code?:string;/** A publishable key (pk_…) for an anonymous visitor; the exchange creates a new anonymous end user bound to the request Origin, unless continuation_token continue */ publishable_key?:string;/** The continuation_token of an earlier anonymous answer, kept by the page's own storage. */ continuation_token?:string}}):Promise<{/** Object type, always customer_access_token. */ type?:"customer_access_token";/** The bearer token to send as `Authorization: Bearer <access_token>`; it lasts at most two hours and never outlives the sign-in. */ access_token?:string;/** RFC 3339 time this token stops working; renew before it with access_tokens/renew. */ expires_at?:string;/** RFC 3339 time the sign-in itself ends; a renewal never extends it. */ session_expires_at?:string;/** Id of the sign-in (csi_…) this token was issued from, which the renewal and the sign-out act on. */ sign_in_id?:string;/** Present on an anonymous answer only. */ continuation_token?:string;/** The end user the token belongs to. */ customer?:{/** End-user id (the merchant's own value, or anon_… for a visitor). */ id:string;/** Kind of end user: identified for one that signed in through a grant code, anonymous for a visitor admitted with a publishable key. */ type:"identified"|"anonymous"}}>;

Parameters

NameInTypeRequiredDescription
OriginheaderstringnoBrowser page origin the exchange is made from, for example https://school.example.com. Send it when the sign-in is bound to one; the service compares it with the binding and refuses a mismatch.

Request body

RequiredContent typesDescription
yesapplication/jsonExactly one credential to exchange: a grant code from grant_codes, or a publishable key for an anonymous visitor.

Responses

StatusContent typesDescription
201application/jsonThe new access token, the sign-in behind it and the end user it belongs to.
400application/jsonINVALID_PARAMS: the request is not shaped the way this face accepts — an unknown or misspelled field, a repeated query parameter, a resource scope not in the form <type>:<id>:<action>, an expand value that is not products, sign_ins or usage, or a confirm that does not repeat the path customer id. The error names the field at fault and what it accepts; correct that field and send the request again.
401application/jsonThe credential is missing, malformed or expired. Merchant routes answer UNAUTHENTICATED when the API key or session names no organization; the pre-auth doors answer GRANT_CODE_INVALID when a grant code is unknown, already used, expired or foreign, and ACCESS_TOKEN_EXPIRED when the end-user token cannot be verified (a sign-in that is over answers SIGN_IN_EXPIRED or SIGN_IN_REVOKED). Send a valid API key, request a fresh grant code, or sign the end user in again.
403application/jsonThe credential is valid but the call is refused: ORIGIN_NOT_ALLOWED when the request Origin does not satisfy the sign-in or grant binding, CUSTOMER_BLOCKED when the directory has blocked that end user, RESOURCE_NOT_GRANTED when the resource asked for is outside what the sign-in carries. Fix the cause the message names — send the bound origin, unblock the end user, or grant the resource in the next grant code — then retry.
429application/jsonOne of four limits on the exchange, each with a Retry-After header in seconds. RATE_LIMITED: the caller IP has spent this door per-minute anonymous budget. PUBLISHABLE_KEY_RATE_LIMITED: the publishable key has spent its anon_rate_per_min exchanges for this UTC minute, whoever sent them; Retry-After is the rest of the minute. PUBLISHABLE_KEY_DAILY_CAP_REACHED: the key has admitted daily_session_cap new anonymous visitors in this UTC day; a new visitor is refused until 00:00 UTC (Retry-After), while a returning visitor that sends its continuation_token is still admitted. PUBLISHABLE_KEY_DAILY_SPEND_CAP_REACHED: what the usage of this key has cost in this UTC day reached its daily_spend_cap; every visitor, a returning one included, is refused until 00:00 UTC (Retry-After). Wait before retrying, never retry immediately; raise or clear the key limit with praxis.customer.publishableKeys.update if it is set too low.
502application/jsonUPSTREAM_UNAVAILABLE: the token issuer or another dependency refused the call, so nothing was issued or changed. Retry later, and if it persists report the time and the request path.
503application/jsonUPSTREAM_UNAVAILABLE: this face is not usable in this environment — the CUSTOMER service binding is unwired, or the anonymous rate limiter is unavailable or misconfigured so the door fails closed. Use an environment where the face is wired, or retry when the dependency is back.