JavaScript Virtual Try-On SDK
DressApp's JavaScript SDK embeds AI virtual try-on on any web storefront. Add one backend session route and a lightweight script to put a Try it on button on product pages — model creation, try-on, and add-to-cart run on the page.
Packages
DressApp ships a browser SDK that wraps sessions, model studio, and try-on calls.
@dressapp/web-sdk- - lightweight JS (
DressApp.enable()- , try-on buttons, model studio redirect).
@dressapp/react-widget- - React components (floating studio dock, inline PDP widget). Built on the web SDK.
Setup steps
Credentials & storefront URL
Credentials & storefront URL
Open Credentials in Settings. Copy your publishable key (
dress_pk_…) and secret key (dress_sk_…). Keep the secret key on your server only - never in browser code.On the same page, enter and save your storefront URL - the public site where try-on runs (e.g.
https://your-store.com). DressApp uses this to allow your domain for SDK calls.Add the keys to your backend environment (secrets manager or
.env):Server environmentDRESSAPP_API_BASE_URL=https://api.dressapp.me DRESSAPP_MERCHANT_SECRET=dress_sk_live_… # Optional: expose publishable key to the browser DRESSAPP_PUBLISHABLE_KEY=dress_pk_live_… NEXT_PUBLIC_DRESSAPP_PUBLISHABLE_KEY=dress_pk_live_… NEXT_PUBLIC_DRESSAPP_API_BASE_URL=https://api.dressapp.meRestart your server after updating env vars so session and product routes pick up the new values.
Backend: shopper session
Backend: shopper session
Add one route on your server, for example
GET /api/dressapp-session. It calls DressApp with your secret key and returns theaccess_tokento your frontend.POST /partner/v1/sessionsAuthorization: Bearer dress_sk_live_… { "external_user_ref": "<stable shopper id>" } // Response: { "access_token": "…" }Use your logged-in customer ID, or a persistent anonymous cookie ID for guests.
Backend: product sync
Backend: product sync
When products are created or updated, call
POST /partner/v1/productswith the same secret key. Save the returnedproduct_idnext to that SKU.POST /partner/v1/products{ "external_id": "SKU-001", "title": "Blue dress", "url": "https://yoursite.com/p/blue-dress", "image_urls": ["https://yoursite.com/img/1.jpg"], "sizes": ["XS", "S", "M", "L"], "colors": [{"label": "Navy"}, {"label": "Black"}] }Frontend: PDP product context
Frontend: PDP product context
On every product page, always pass
externalProductId,fallbackSizesJson, andfallbackColorsJsonto the dock - even when you already have a DressAppproductId. The SDK callsGET /partner/v1/embed/resolve-productto map your SKU to a catalog row and backfill sizes/colors. Any PDP URL structure works - passing the product explicitly is what marks the page as a product page.PartnerStudioDock (React)<PartnerStudioDock publishableKey="dress_pk_live_…" apiBase="https://api.dressapp.me" getAccessToken={…} productId={dressAppProductId} externalProductId="SKU-001" storeProductUrl={window.location.href} fallbackSizesJson='["XS","S","M","L"]' fallbackColorsJson='[{"label":"Navy"},{"label":"Black"}]' mountPdpTryonButton />Frontend: PDP Try it on button
Frontend: PDP Try it on button
Give the inline button a mount point on your product template - one of three options:
- A placeholder slot right above your Add to cart button:
<div data-dressapp-pdp-tryon-block></div>- (most reliable).
- Mark your buy button with
data-dressapp-pdp-anchor- - the button injects above it.
- Pass
pdpAnchorSelector="#add-to-cart"- (React prop, mount option, or
data-pdp-anchor-selector- attr).
Product template<div class="product-actions"> <div data-dressapp-pdp-tryon-block></div> <button id="add-to-cart">Add to cart</button> </div>The button runs the full flow on-page: size pills, Front/Back picker, model creation modal for first-time shoppers, inline progress cards, and a result modal.
Frontend: install the SDK
Frontend: install the SDK
npmnpm install @dressapp/web-sdk # Or for React: npm install @dressapp/react-widgetFrontend: enable DressApp
Frontend: enable DressApp
After you fetch the shopper token from your backend:
Enable SDKimport { DressApp } from "@dressapp/web-sdk"; await DressApp.enable({ publishableKey: "dress_pk_live_…", apiBase: "https://api.dressapp.me", accessToken: shopperJwt, });Cart hookup & SPA navigation
Cart hookup & SPA navigation
Register your cart once so the try-on result modal shows Add tried size to cart. Throw an error containing "out of stock" to surface the out-of-stock state.
Add to cart handlerDressApp.setAddToCartHandler(async ({ productPageUrl, sizeLabel, colorLabel }) => { await myCart.add({ url: productPageUrl, size: sizeLabel, color: colorLabel }); }, { cartUrl: "/cart" });On single-page apps, rebind the product on route changes instead of reloading:
SPA navigationDressApp.setProduct({ externalProductId: "SKU-002", storeProductUrl: location.href, fallbackSizesJson: '["S","M","L"]', fallbackColorsJson: '[{"label":"White"}]', }); DressApp.setProduct({}); // clear when leaving product pagesFirst visit: create a model
First visit: create a model
No redirect needed. When a shopper without a body model presses Try it onon the PDP, a theme-matched modal opens on the page (photos → details → model ready). The floating dock's My Model tab offers the same wizard when enabled.
Try-on
Try-on
On the PDP: press Try it on, pick a size and Front/Back angle, and the try-on runs inline with a progress card and a result modal. Headless alternative for custom UIs:
Request try-on (headless)await DressApp.requestTryOn(productId, { async: true }) // Poll until complete: DressApp.getTryOnJob(jobId)Ship it
Ship it
Test the full path on HTTPS: session → PDP Try it on → model modal → inline try-on → result modal (+ add-to-cart when wired) on a real product.