Record an order (idempotent by order ID)
const url = 'https://api.tryyoursize.com/v1/orders';const options = { method: 'POST', headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'}, body: '{"id":"example","ordered_at":"2026-04-15T12:00:00Z","currency":"example","visitor_id":"example","experiment_arm":"treatment","lines":[{"id":"example","product":"example","variant":"example","size":"example","quantity":1,"unit_price_minor":1,"tys_shown":true,"recommended_size":"example","attribution":"cart_attribute"}]}'};
try { const response = await fetch(url, options); const data = await response.json(); console.log(data);} catch (error) { console.error(error);}curl --request POST \ --url https://api.tryyoursize.com/v1/orders \ --header 'Authorization: Bearer <token>' \ --header 'Content-Type: application/json' \ --data '{ "id": "example", "ordered_at": "2026-04-15T12:00:00Z", "currency": "example", "visitor_id": "example", "experiment_arm": "treatment", "lines": [ { "id": "example", "product": "example", "variant": "example", "size": "example", "quantity": 1, "unit_price_minor": 1, "tys_shown": true, "recommended_size": "example", "attribution": "cart_attribute" } ] }'Key scopes: orders:write. A secret key (sk_) has every scope; a restricted key (rk_) needs the scopes listed.
From the brand’s server with a secret key or a restricted key with orders:write. Re-sending the same id updates the order (200); a new one is 201. The A/B arm comes from visitor_id (recomputed by TryYourSize) or experiment_arm. No customer data is accepted.
Authorizations
Section titled “Authorizations”Request Bodyrequired
Section titled “Request Bodyrequired”An order from the brand’s server. Re-sending the same id updates it (idempotent). No customer data: there is no customer, email, name or address field, and unknown fields are refused.
object
Your order ID.
ISO 4217, e.g. EUR.
The SDK’s anonymous visitor ID ((await tys.experiment())?.visitorId), saved with the cart. TryYourSize recomputes the A/B arm from it and stores only its hash. Never a customer ID.
The arm, when you cannot send visitor_id.
object
Your order line ID (unique within the order).
Your product ID (the one you pass to the SDK).
The size bought, in your labels.
Price of one unit in minor units (5995 = 59.95). Optional; used for the refund value estimate.
A TryYourSize element was shown for this purchase.
The size TryYourSize recommended (the SDK’s recommendation event, or the _tys_size cart line property).
Where recommended_size came from.
Responses
Section titled “Responses”Updated
object
False when the order already existed and was updated.
Example
{ "experiment_arm": "treatment"}Created
object
False when the order already existed and was updated.
Example
{ "experiment_arm": "treatment"}Invalid request
Every error has this shape. error is a human-readable message, status the HTTP status. code is stable and machine-readable; doc_url links its explanation; request_id identifies the request (also in the X-Request-ID response header): quote it to support.
object
Stable error code, e.g. invalid_request, unauthorized, reauth_required, payment_required, forbidden, not_found, conflict, unprocessable, rate_limited, internal_error, not_implemented, unavailable, invalid_api_version, idempotency_key_in_use, idempotency_key_reused, invalid_idempotency_key, handle_expired, handle_invalid.
Example
{ "code": "not_found", "doc_url": "https://docs.tryyoursize.com/api/errors/#not_found"}Missing or invalid credentials
Every error has this shape. error is a human-readable message, status the HTTP status. code is stable and machine-readable; doc_url links its explanation; request_id identifies the request (also in the X-Request-ID response header): quote it to support.
object
Stable error code, e.g. invalid_request, unauthorized, reauth_required, payment_required, forbidden, not_found, conflict, unprocessable, rate_limited, internal_error, not_implemented, unavailable, invalid_api_version, idempotency_key_in_use, idempotency_key_reused, invalid_idempotency_key, handle_expired, handle_invalid.
Example
{ "code": "not_found", "doc_url": "https://docs.tryyoursize.com/api/errors/#not_found"}Not allowed
Every error has this shape. error is a human-readable message, status the HTTP status. code is stable and machine-readable; doc_url links its explanation; request_id identifies the request (also in the X-Request-ID response header): quote it to support.
object
Stable error code, e.g. invalid_request, unauthorized, reauth_required, payment_required, forbidden, not_found, conflict, unprocessable, rate_limited, internal_error, not_implemented, unavailable, invalid_api_version, idempotency_key_in_use, idempotency_key_reused, invalid_idempotency_key, handle_expired, handle_invalid.
Example
{ "code": "not_found", "doc_url": "https://docs.tryyoursize.com/api/errors/#not_found"}Was this page helpful?
Thank you. We read every answer.