# Set or adjust stock

Sets or adjusts a stock. Works with Shopify and WooCommerce accounts.

```http
POST https://api.pozy.ai/v1/commerce/products/{productId}/inventory
```

- Area: Commerce / Commerce
- Auth: Authorization: Bearer pz_live_...

## Path parameters

- `productId` (string, required)

## Request body

Content type: `application/json`

- `accountId`, string, required
- `mode`, string: One of `set`, `adjust`. Default `set`
- `changes`, array of object, required: At least 1 item. Up to 250 items
  - `variantId`, string, required
  - `locationId`, string, required
  - `quantity`, integer, required

## Example request

```bash
curl -X POST "https://api.pozy.ai/v1/commerce/products/659773d34b353e6821202f21/inventory" \
  -H "Authorization: Bearer $POZY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "accountId": "696e0b682d0a31188e7a2ba9",
  "changes": [
    {
      "variantId": "64058b146247283881d19961",
      "locationId": "6e99c3dd69982b334a43b0b2",
      "quantity": 1
    }
  ]
}'
```

```ts
const res = await fetch("https://api.pozy.ai/v1/commerce/products/659773d34b353e6821202f21/inventory", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.POZY_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    accountId: "696e0b682d0a31188e7a2ba9",
    changes: [
      {
        variantId: "64058b146247283881d19961",
        locationId: "6e99c3dd69982b334a43b0b2",
        quantity: 1
      }
    ]
  }),
});
const data = await res.json();
if (!res.ok) throw new Error(data?.error ?? `Request failed with status ${res.status}`);
console.log(data);
```

```python
import os
import requests

resp = requests.post(
    "https://api.pozy.ai/v1/commerce/products/659773d34b353e6821202f21/inventory",
    headers={"Authorization": f"Bearer {os.environ['POZY_API_KEY']}"},
    json={
        "accountId": "696e0b682d0a31188e7a2ba9",
        "changes": [
            {
                "variantId": "64058b146247283881d19961",
                "locationId": "6e99c3dd69982b334a43b0b2",
                "quantity": 1,
            },
        ],
    },
    timeout=30,
)
resp.raise_for_status()
print(resp.json())
```

## Response 200

- `inventory`, array of object
  - `productId`, string
  - `variantId`, string
  - `sku`, string: Can be null
  - `tracked`, boolean
  - `levels`, array of object
    - `locationId`, string
    - `available`, integer: Can be null
    - `onHand`, integer: Can be null
    - `committed`, integer: Can be null
    - `incoming`, integer: Can be null

```json
{
  "inventory": [
    {
      "productId": "659773d34b353e6821202f21",
      "variantId": "64058b146247283881d19961",
      "sku": "string",
      "tracked": true,
      "levels": [
        {
          "locationId": "6e99c3dd69982b334a43b0b2",
          "available": 1,
          "onHand": 1,
          "committed": 1,
          "incoming": 1
        }
      ]
    }
  ]
}
```
