# tys.orders.create()

> Record an order (idempotent by order id; re-sending updates it).

Source: https://docs.tryyoursize.com/reference/python/orders-create/

*Method* · `tryyoursize`

Record an order (idempotent by order `id`; re-sending updates it). No customer data.

```python
def create(order: OutcomeOrderInput, *, idempotency_key: Optional[str] = None) -> OutcomeOrderResult
```

## Parameters

- **`order`** (`OutcomeOrderInput`, required)
  - **`id`** (`string`, required): Your order ID.
  - **`ordered_at`** (`string`, required)
  - **`currency`** (`string`, optional): ISO 4217, e.g. EUR.
  - **`visitor_id`** (`string`, optional): The SDK's anonymous visitor ID (`(await tys.experiment())?.visitorId`), saved with the cart. TryYourSize recomputes the A/B arm from it and stores only its hash. Never a customer ID.
  - **`experiment_arm`** (`"treatment" | "holdout"`, optional): The arm, when you cannot send visitor_id.
  - **`lines`** (`OutcomeLineInput[]`, required)
    - **`id`** (`string`, required): Your order line ID (unique within the order).
    - **`product`** (`string`, required): Your product ID (the one you pass to the SDK).
    - **`variant`** (`string`, optional)
    - **`size`** (`string`, required): The size bought, in your labels.
    - **`quantity`** (`integer`, required)
    - **`unit_price_minor`** (`integer`, optional): Price of one unit in minor units (5995 = 59.95). Optional; used for the refund value estimate.
    - **`tys_shown`** (`boolean`, optional): A TryYourSize element was shown for this purchase.
    - **`recommended_size`** (`string`, optional): The size TryYourSize recommended (the SDK's recommendation event, or the _tys_size cart line property).
    - **`attribution`** (`"cart_attribute" | "sdk" | "api"`, optional): Where recommended_size came from.
- **`idempotency_key`** (`Optional[str]`, optional, default `None`)

## Returns

`OutcomeOrderResult`: What was recorded.

- **`id`** (`string`, required)
- **`external_id`** (`string`, required)
- **`created`** (`boolean`, required): False when the order already existed and was updated.
- **`experiment_arm`** (`"treatment" | "holdout"`, optional)
- **`lines`** (`integer`, required)

## Example

**Python**

```python
from datetime import datetime, timezone

tys.orders.create({
    "id": "1001",
    "ordered_at": datetime.now(timezone.utc).isoformat(),
    "currency": "EUR",
    "visitor_id": visitor_id,
    "lines": [{"id": "1", "product": "TEE-001", "size": "M", "quantity": 1,
               "recommended_size": "M", "tys_shown": True}],
})
```

**Node.js**

```ts
await tys.orders.create({
  id: "1001",                       // your order ID: re-sending updates it
  ordered_at: new Date().toISOString(),
  currency: "EUR",
  visitor_id,                       // from tys.experiment() in the browser, saved with the cart
  lines: [
    { id: "1", product: "TEE-001", size: "M", quantity: 1, recommended_size: "M", tys_shown: true },
  ],
});
```

**cURL**

```bash
curl -X POST https://api.tryyoursize.com/v1/orders \
  -H "Authorization: Bearer $TRYYOURSIZE_SECRET_KEY" \
  -H "TYS-Version: 2026-10-25" \
  -H "Content-Type: application/json" \
  -d '{"id":"1001","ordered_at":"2026-10-26T10:00:00Z","lines":[{"id":"1","product":"TEE-001","size":"M","quantity":1}]}'
```

## See also

- [Orders and returns](https://docs.tryyoursize.com/guides/outcomes.md)
- [orders.create (HTTP API)](https://docs.tryyoursize.com/api/reference/operations/createoutcomeorder.md)
