# Node.js reference (@tryyoursize/node)

> The server SDK for Node.js 18+: recommendations, catalog, orders and returns, audit log, webhooks.

Source: https://docs.tryyoursize.com/reference/node/

*SDK* · `@tryyoursize/node` · v0.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`).

## Install

**npm**

```bash
npm install @tryyoursize/node
```

**pip**

```bash
pip install tryyoursize
```

## Initialize

**Node.js**

```ts

const tys = new TryYourSize(process.env.TRYYOURSIZE_SECRET_KEY!, {
  maxRetries: 2,      // network errors, timeouts, 429, 5xx
  timeoutMs: 30_000,
});
```

**Python**

```python

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](https://docs.tryyoursize.com/api/reference.md). Errors are typed: see [Errors](https://docs.tryyoursize.com/reference/node/errors.md) and the [API error codes](https://docs.tryyoursize.com/api/errors.md).

## Client

| | |
|---|---|
| [`new TryYourSize()`](https://docs.tryyoursize.com/reference/node/client.md) | Creates a client for one secret or restricted key. |
| [`mode`](https://docs.tryyoursize.com/reference/node/mode.md) | "test" or "live", from the key prefix. |
| [`lastResponse`](https://docs.tryyoursize.com/reference/node/last-response.md) | Meta of the last answered request (success or API error). |
| [`RequestOptions`](https://docs.tryyoursize.com/reference/node/request-options.md) | Options of one call: the last argument of every method. |

## Recommendations

| | |
|---|---|
| [`recommendations.create()`](https://docs.tryyoursize.com/reference/node/recommendations-create.md) | handle comes from the browser SDK (await tys.recommendationHandle()), products are your SKUs / style IDs. |

## Products

| | |
|---|---|
| [`products.list()`](https://docs.tryyoursize.com/reference/node/products-list.md) | Newest first. |
| [`products.create()`](https://docs.tryyoursize.com/reference/node/products-create.md) | tys.products.create() |
| [`products.retrieve()`](https://docs.tryyoursize.com/reference/node/products-retrieve.md) | tys.products.retrieve() |
| [`products.update()`](https://docs.tryyoursize.com/reference/node/products-update.md) | Replaces the SKU, name and category (all three required). |
| [`products.sizeMap.retrieve()`](https://docs.tryyoursize.com/reference/node/products-size-map-retrieve.md) | tys.products.sizeMap.retrieve() |
| [`products.sizeMap.save()`](https://docs.tryyoursize.com/reference/node/products-size-map-save.md) | Replaces the size map. |
| [`products.garments.list()`](https://docs.tryyoursize.com/reference/node/products-garments-list.md) | Garment versions, newest first (a single page: has_more is always false). |
| [`products.garments.createDraft()`](https://docs.tryyoursize.com/reference/node/products-garments-create-draft.md) | Starts a new draft version (sizes, POMs in mm, grading, fabric). |

## Garments

| | |
|---|---|
| [`garments.retrieve()`](https://docs.tryyoursize.com/reference/node/garments-retrieve.md) | tys.garments.retrieve() |
| [`garments.updateDraft()`](https://docs.tryyoursize.com/reference/node/garments-update-draft.md) | Replaces a draft's content (published versions never change: 409). |
| [`garments.publish()`](https://docs.tryyoursize.com/reference/node/garments-publish.md) | Publishes a complete draft. |

## Fit groups

| | |
|---|---|
| [`fitGroups.list()`](https://docs.tryyoursize.com/reference/node/fit-groups-list.md) | tys.fitGroups.list() |
| [`fitGroups.create()`](https://docs.tryyoursize.com/reference/node/fit-groups-create.md) | tys.fitGroups.create() |
| [`fitGroups.retrieve()`](https://docs.tryyoursize.com/reference/node/fit-groups-retrieve.md) | tys.fitGroups.retrieve() |
| [`fitGroups.linkProducts()`](https://docs.tryyoursize.com/reference/node/fit-groups-link-products.md) | Moves products into the group (they then use its garment). |

## Outcomes

| | |
|---|---|
| [`orders.create()`](https://docs.tryyoursize.com/reference/node/orders-create.md) | tys.orders.create() |
| [`returns.create()`](https://docs.tryyoursize.com/reference/node/returns-create.md) | tys.returns.create() |

## Audit log

| | |
|---|---|
| [`auditEvents.list()`](https://docs.tryyoursize.com/reference/node/audit-events-list.md) | tys.auditEvents.list() |

## Webhooks

| | |
|---|---|
| [`webhooks.constructEvent()`](https://docs.tryyoursize.com/reference/node/webhooks-construct-event.md) | Verifies a delivery's TYS-Signature header against the raw request body and returns the parsed event. |
| [`webhooks.verifySignature()`](https://docs.tryyoursize.com/reference/node/webhooks-verify-signature.md) | Checks the signature only (throws when it does not verify). |
| [`webhooks.generateTestHeader()`](https://docs.tryyoursize.com/reference/node/webhooks-generate-test-header.md) | Builds a valid TYS-Signature header for a payload, to test your webhook handler. |

## Pagination and errors

| | |
|---|---|
| [`PagePromise`](https://docs.tryyoursize.com/reference/node/page-promise.md) | 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`](https://docs.tryyoursize.com/reference/node/errors.md) | 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 |
