Ir al contenido

Node.js reference (@tryyoursize/node)

Esta página aún no está disponible en tu idioma.

SDK@tryyoursize/nodev0.1.0

The official Node.js SDK for the TryYourSize server API. Use it on your server with a secret key (sk_test_… / sk_live_…) or a restricted key (rk_…); publishable keys (pk_…) are refused. Typed from our OpenAPI spec, with retries, idempotency keys and auto-pagination built in. Node 18 or newer (or pass your own fetch).

Terminal window
npm install @tryyoursize/node
import TryYourSize from "@tryyoursize/node";
const tys = new TryYourSize(process.env.TRYYOURSIZE_SECRET_KEY!, {
maxRetries: 2, // network errors, timeouts, 429, 5xx
timeoutMs: 30_000,
});

Every method maps to one HTTP operation of the HTTP API reference. Errors are typed: see Errors and the API error codes.

new TryYourSize() Creates a client for one secret or restricted key.
mode “test” or “live”, from the key prefix.
lastResponse Meta of the last answered request (success or API error).
RequestOptions Options of one call: the last argument of every method.
recommendations.create() handle comes from the browser SDK (await tys.recommendationHandle()), products are your SKUs / style IDs.
products.list() Newest first.
products.create() tys.products.create()
products.retrieve() tys.products.retrieve()
products.update() Replaces the SKU, name and category (all three required).
products.sizeMap.retrieve() tys.products.sizeMap.retrieve()
products.sizeMap.save() Replaces the size map.
products.garments.list() Garment versions, newest first (a single page: has_more is always false).
products.garments.createDraft() Starts a new draft version (sizes, POMs in mm, grading, fabric).
garments.retrieve() tys.garments.retrieve()
garments.updateDraft() Replaces a draft’s content (published versions never change: 409).
garments.publish() Publishes a complete draft.
fitGroups.list() tys.fitGroups.list()
fitGroups.create() tys.fitGroups.create()
fitGroups.retrieve() tys.fitGroups.retrieve()
fitGroups.linkProducts() Moves products into the group (they then use its garment).
orders.create() tys.orders.create()
returns.create() tys.returns.create()
auditEvents.list() tys.auditEvents.list()
webhooks.constructEvent() Verifies a delivery’s TYS-Signature header against the raw request body and returns the parsed event.
webhooks.verifySignature() Checks the signature only (throws when it does not verify).
webhooks.generateTestHeader() Builds a valid TYS-Signature header for a payload, to test your webhook handler.
PagePromise What every list() returns: await it for one page ({ data, has_more, next_cursor }), or iterate it with for await to walk every item of every page.
Errors Every error of an API call is a TryYourSizeError subclass, by HTTP status: InvalidRequestError (400, 422), AuthenticationError (401), PermissionError (403), NotFoundError (404), ConflictError (409), R

¿Te ha resultado útil esta página?