Node.js reference (@tryyoursize/node)
Esta página aún no está disponible en tu idioma.
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).
Install
Section titled “Install”npm install @tryyoursize/nodepip install tryyoursizeInitialize
Section titled “Initialize”import TryYourSize from "@tryyoursize/node";
const tys = new TryYourSize(process.env.TRYYOURSIZE_SECRET_KEY!, { maxRetries: 2, // network errors, timeouts, 429, 5xx timeoutMs: 30_000,});import osimport tryyoursize
tys = tryyoursize.TryYourSize(os.environ["TRYYOURSIZE_SECRET_KEY"], max_retries=2, timeout=30.0)Every method maps to one HTTP operation of the HTTP API reference. Errors are typed: see Errors and the API error codes.
Client
Section titled “Client”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
Section titled “Recommendations”recommendations.create() |
handle comes from the browser SDK (await tys.recommendationHandle()), products are your SKUs / style IDs. |
Products
Section titled “Products”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
Section titled “Garments”garments.retrieve() |
tys.garments.retrieve() |
garments.updateDraft() |
Replaces a draft’s content (published versions never change: 409). |
garments.publish() |
Publishes a complete draft. |
Fit groups
Section titled “Fit groups”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). |
Outcomes
Section titled “Outcomes”orders.create() |
tys.orders.create() |
returns.create() |
tys.returns.create() |
Audit log
Section titled “Audit log”auditEvents.list() |
tys.auditEvents.list() |
Webhooks
Section titled “Webhooks”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. |
Pagination and errors
Section titled “Pagination and errors”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?
Gracias. Leemos todas las respuestas.