Widget preflight

get/v1/widget/preflight

Tells an embed whether the widget can be shown for the organization behind the public key, and hands back everything it needs to do so: the resolved theme colours and an analytics session token. The Stylor embed script calls this once per page load; call it yourself if you host your own launcher.

Readiness

ready is true when the organization has at least one active dataset. When you pass datasetIds, readiness is judged on those datasets instead: ready is true if at least one of them belongs to your organization and is not archived, so a scope made only of draft datasets is ready. This is the same rule search applies to an explicit datasetIds. The organization's plan must also cover what the widget spends: ready is false when it has no active plan, when the plan does not include the chat or outfit renders, or when either's allowance is used up for the billing period, so a launcher that would only fail is never shown. When not ready, ready is false with a reason saying which, the HTTP status is still 200, and no session is issued; there is nothing to measure if the widget is not shown. The theme and strings are returned in every case.

The checks run in this order, and reason is the first that fails:

reason When
The widget is switched off in this organization's Stylor settings. The widgets are switched off (also code: widget_disabled).
No active datasets found for this organization. No datasetIds were sent and no dataset is active.
None of the requested datasets exist in this organization or all of them are archived. datasetIds were sent and none of them is usable.
This organization has no active plan. The organization has no plan allowances for the current billing period.
This plan does not include the chat. / This plan does not include outfit renders. The plan leaves one of them out.
The allowance for the chat is used up for this billing period. / The allowance for outfit renders is used up for this billing period. One of them has no allowance left.

Theme

The flat theme object holds the colours and launcher label the widget should render with. It is resolved in this order: the preset named by themeId if it belongs to your organization; otherwise your most recently modified preset; otherwise Stylor's defaults. An unknown themeId is not an error — it silently falls through to the next rule. Any colour a preset leaves unset falls back to the default for that key. roundness is served from 0 (square corners) to 1 (as shipped); a preset stores it from 0 to 100.

themeId=none asks for no theme: Stylor's defaults, whatever presets exist. theme.source says which you got — preset for a saved theme, default for Stylor's defaults — so an embed that would rather take the store's own look (as complete the look takes the store's button corners) knows when nobody chose these values.

Language

Send the page's language as lang (a tag such as fr or pt-BR) and the launcher's own text comes back in it: strings holds the button titles, and theme.buttonLabel is the theme's translation of its label for that language when one exists (made automatically for the languages your stores show pages in, or written by you in the theme editor), else Stylor's own label in that language when the theme kept the default label, else the label as written. A language the widget has no text for gets English.

Price report

On a product page the Stylor embed also sends how the storefront shows prices to this shopper: the page's currency (cur) and conversion rate (rate), the product's price as shown (price), the product's sku, name and URL (purl), and the shopper's country. Stylor uses it to learn the store's currency conversion and rounding, so the chat and the dashboard show prices the way the storefront does. It is recorded only when the widget is ready, at most once an hour per organization, currency and country, and never changes or delays the response. Leave these parameters out unless you build your own embed and want the same behaviour.

Analytics session

session.token is the credential for the events endpoint. Send it as the X-Stylor-Session header on every POST /v1/events. It is bound to your organization and, when the request carried an Origin header, to that storefront origin. It expires after expiresIn seconds (two hours); calling preflight again issues a fresh one.

Pass the previous session.sessionId back as sid on the next page load so a shopper browsing several pages stays one session. A sid that is not a UUID is ignored and a new id is minted. session is null when the server cannot sign tokens; the widget still loads, it simply sends no analytics.

Widgets switched off

When the organization has switched its widgets off (PATCH /v1/widget/settings with enabled: false, or the switch in its settings), ready is false with code: widget_disabled, on every store and from the next call; nothing is cached.

Holdout test

When the organization runs a holdout test (holdoutPercent in /v1/widget/settings), that share of visits never sees the chat widget, so its lift can be measured. An embed takes part by sending holdout=1; one that does not is never put in the test. experiment then says which arm the visit is in. arm: holdout means: leave the launcher out, but keep the session and send events (page views and cart adds), because those visits are what the widget is measured against. The arm is signed into session.token, so every event of the visit is filed under it. Keep experiment.ticket for the tab and send it back as xt, so the visit keeps its arm on every page.

CORS

The route answers OPTIONS preflight with 204 and allows any origin, so it can be called directly from a storefront page.

Public keyapi.v1.widget.preflightDemo key OK

Query parameters

15
themeIdstring

Id of a widget theme preset belonging to your organization. Falls back to the most recently modified preset, then to defaults, when absent or unknown.

datasetIdsstring

Comma-separated dataset ids the widget is scoped to. When present, readiness counts these datasets (draft included, archived excluded) instead of the organization's active datasets. At most 50 ids are read.

sidstring (uuid)

The session.sessionId from an earlier preflight in the same browser tab, so navigation within the store stays one visit. Must be a UUID; anything else is ignored and a new session id is minted.

holdoutstring

1 when the embed can leave the launcher out for a visit in the holdout arm. Without it the visit is never in the organization's holdout test and experiment is null.

1
vidstring

The embed's visitor id (v- and letters and digits), sent only when the storefront's consent allows keeping one. When present the holdout splits on it, so a returning shopper stays in their arm; otherwise on the visit.

xtstring

The experiment.ticket from an earlier preflight of this visit, so the visit keeps its arm. Ignored unless it is for this sid and the test running now.

armstring

Forces this visit's arm, widget or holdout, for checking your own store. A forced visit is marked forced and left out of the results.

widgetholdout
langstring

The page's language, a BCP 47 tag such as fr, de-CH or zh-TW. The launcher's label and strings come back in it; an unknown or missing tag gets English.

curstring

Price report. The currency the storefront shows this shopper, a three-letter ISO 4217 code (on Shopify, Shopify.currency.active). The report is ignored unless cur, rate and price are all valid.

ratenumber

Price report. The storefront's conversion rate from the store's currency to cur (on Shopify, Shopify.currency.rate). Greater than 0 and at most 100000.

max: 100000
pricenumber

Price report. The product's price as the page shows it, in cur. Greater than 0.

skustring

Price report. The SKU of the variant whose price the page shows. At most 256 characters; a longer value is ignored.

maxLength: 256
namestring

Price report. The product's name, used to find it when no SKU matches. At most 256 characters.

maxLength: 256
purlstring

Price report. The product page's URL, used to find the product. At most 1024 characters.

maxLength: 1024
countrystring

Price report. The shopper's country, an ISO 3166-1 alpha-2 code (on Shopify, Shopify.country). Anything else is ignored.

Headers

1
Originstring

Set automatically by browsers. When present it is recorded in the session token, and later event batches from a different origin are refused.

Response

200Readiness, theme and (when ready) the analytics session.
readybooleanrequired

true when the widget may be shown: switched on, a dataset in scope, and a plan that covers the chat and outfit renders with allowance left.

e.g. true
reasonstring

Only present when ready is false. Why the widget is not shown; the messages are listed under Readiness above.

e.g. "No active datasets found for this organization."
codestring

Present when ready is false because the organization switched its widgets off.

One ofwidget_disabled
momentsboolean

true when the organization has the chat widget offer help before it is asked (its moments setting); the widget script then loads its prompts. Present only when ready is true.

tryOnButtonboolean

true when the organization put "Try it on" on product photos (its tryOnButton setting) and "See it on you" is allowed for the store the page is on; the widget script then draws the button. Present only when ready is true.

object | nullnullable

The visit's arm in the organization's holdout test, or null when it is in none (no test running, holdout=1 not sent, or no session). Present only when ready is true.

Option 1: object

idstringrequired

The test. A new id each time the organization changes the share.

armstringrequired

holdout: leave the launcher out for this visit, but keep sending events.

One ofwidgetholdout
forcedbooleanrequired

The arm was forced with arm; the visit is left out of the results.

ticketstringnullablerequired

Send back as xt on the visit's next preflight.

Option 2: null

WidgetThemerequired

Flat set of colours (CSS hex), the launcher label, the corner roundness and where they came from. Every key is always present; unset preset values fall back to the defaults shown.

buttonBgstringrequired

Launcher button background.

default: "#2D2926"
buttonHoverstringrequired

Launcher button background on hover.

default: "#231F1C"
buttonTextstringrequired

Launcher button text colour.

default: "#FFFFFF"
buttonLabelstringrequired

Launcher button label, in the page's language when lang was sent and a translation exists (see Language above).

default: "Style me with Stylor"
roundnessnumberrequired

Corner roundness for the whole widget, 0 (square) to 1 (as shipped). The preset's 0 to 100 divided by 100.

default: 1min: 0max: 1
typingDotstringrequired

Colour of the typing indicator dots.

default: "#2D2926"
accentstringrequired

Primary accent inside the panel.

default: "#2D2926"
accentHoverstringrequired

Accent on hover.

default: "#4B4641"
textMutedstringrequired

Secondary text colour.

default: "#434656"
textPrimarystringrequired

Primary text colour.

default: "#1B1C1A"
bgPagestringrequired

Panel page background.

default: "#FFFFFF"
bgSurfacestringrequired

Card and surface background.

default: "#FBF9F5"
borderstringrequired

Border colour.

default: "#C4C5D9"
inputBgstringrequired

Message input background.

default: "#F5F3EF"
footerBgstringrequired

Panel footer background.

default: "#FFFFFF"
sourcestringrequired

preset when the values come from a saved theme, default when they are Stylor's defaults (no theme saved, or themeId=none).

One ofpresetdefault
objectrequired

The launcher's own text in the page's language (lang), English when there is none. Always present.

openstringrequired

Title of the launcher button, e.g. Open chat.

resizestringrequired

Title of the panel's resize handle, e.g. Resize.

closestringrequired

Title of the close button, e.g. Close.

swipestringrequired

Hint on mobile, e.g. Swipe down to close.

tryOnobject

Everything the "Try it on" button on a product's photo says (its label, its explanation, its buttons, its waiting lines and its messages), in the page's language. Present only when tryOnButton is true.

WidgetSession | nullnullable

Present only when ready is true. null when the server cannot issue tokens; the widget should then send no analytics.

Option 1: WidgetSession

tokenstringrequired

Signed session token. Send as X-Stylor-Session on POST /v1/events.

e.g. "eyJ2IjoxLCJzaWQiOiI0ZDJhOWMxZS03YjNmLTRlOGEtOWM2ZC0xZjJlM2E0YjVjNmQiLCJvcmciOiIw..."
sessionIdstring (uuid)required

The session id, lowercase. Equal to sid when a valid one was passed, otherwise newly minted. Pass it back as sid on subsequent page loads.

e.g. "4d2a9c1e-7b3f-4e8a-9c6d-1f2e3a4b5c6d"
expiresInintegerrequired

Seconds until the token expires. Always 7200.

e.g. 7200

Option 2: null

Errors

25

Every error is JSON with a single error string unless noted. Match on the status code; the message is for humans.

This endpoint has no errors of its own beyond the shared set below.

curl -X GET "https://stylor.ai/api/v1/widget/preflight" \
  -H "Authorization: Bearer $STYLOR_API_KEY"
Response · 200
{
  "ready": true,
  "theme": {
    "buttonBg": "#2D2926",
    "buttonHover": "#231F1C",
    "buttonText": "#FFFFFF",
    "buttonLabel": "Style me with Stylor",
    "roundness": 1,
    "typingDot": "#2D2926",
    "accent": "#2D2926",
    "accentHover": "#4B4641",
    "textMuted": "#434656",
    "textPrimary": "#1B1C1A",
    "bgPage": "#FFFFFF",
    "bgSurface": "#FBF9F5",
    "border": "#C4C5D9",
    "inputBg": "#F5F3EF",
    "footerBg": "#FFFFFF",
    "source": "default"
  },
  "strings": {
    "open": "Open chat",
    "resize": "Resize",
    "close": "Close",
    "swipe": "Swipe down to close"
  },
  "session": {
    "token": "eyJ2IjoxLCJzaWQiOiI0ZDJhOWMxZS03YjNmLTRlOGEtOWM2ZC0xZjJlM2E0YjVjNmQiLCJvcmciOiIw...",
    "sessionId": "4d2a9c1e-7b3f-4e8a-9c6d-1f2e3a4b5c6d",
    "expiresIn": 7200
  },
  "experiment": null,
  "moments": false,
  "tryOnButton": false
}