# syncStockLevels mutation


`syncStockLevels` is a GraphQL mutation of the Chameleoon MAX API. Send it as `POST https://max-api.chameleoon.sk/api/v1/graphql` with your API key, see [Chameleoon MAX](/chameleoon-max).

Sets the stock of an externally managed warehouse to the quantities that the external system
that manages the warehouse reports. Call it when you send that system's stock of one or more
product variants as a snapshot.

Each item states all of one variant's stock in the warehouse, in physical units:

- A stock position that the item omits is 0.
- An empty `positions` list means the variant has no stock in the warehouse.
- MAX writes only the difference, as one stock-sync document that no list shows, dated now.
- Receipts, issues and transfers written in MAX that the external system had not recorded at
  `asOf` are kept. The external system reports which ones it holds with
  [`confirmStockInExternalSystem`](/chameleoon-max/mutation/confirm-stock-in-external-system).

#### Permissions

Requires the `stock.sync` and `integration.read` permissions.

#### Repeated calls

A repeat with the same `requestId` and the same input changes nothing and returns what the
first call returned.

#### Items

MAX applies an item whole or refuses it whole, and goes on with the other items. Read each
result's `status`.

- A later call can write a refused item.
- An item is `DEFERRED` when the call has already written 500 movements. Send the item again
  with a new `requestId`.
- `asOf` comes from the external system's clock. It must be newer than the `asOf` last judged
  for the variant in the warehouse (an item that was `APPLIED` or `UNCHANGED`), otherwise the
  item is refused with `STALE_SNAPSHOT`.

#### Errors

| Code | Reason | When |
| --- | --- | --- |
| `NOT_FOUND` | | The warehouse does not exist or is outside your API key's scope. |
| `CONFLICT` | `STOCK_NOT_MASTERED` | No external system manages the warehouse. |
| `CONFLICT` | `SOURCE_ARCHIVED` | The external system that manages the warehouse is archived. |
| `CONFLICT` | `REQUEST_ID_REUSED` | The `requestId` was sent before with other input. |
| `VALIDATION` | | `asOf` is more than 15 minutes ahead of the MAX clock. |
| `VALIDATION` | | More than 100 items or 2000 positions, a negative quantity, a blank `externalId`, or the same item or position twice. |
| `INTERNAL` | | The call lost a race with another write. Retry with the same `requestId`. |

> An error whose path runs below this field does not mean the call failed: the snapshot was
> applied, so do not retry. See [`Mutation`](/chameleoon-max/mutations).

Costs 1 point plus 1 per item and 1 per position, plus its selection.

## Arguments

- `input`: [`SyncStockLevelsInput!`](/chameleoon-max/type/sync-stock-levels-input) · required

## Returns

[`SyncStockLevelsResult!`](/chameleoon-max/type/sync-stock-levels-result)

## Example

**Mutation**

```graphql
mutation syncStockLevels($input: SyncStockLevelsInput!) {
  syncStockLevels(input: $input) {
    items {
      index
      externalId
      status
      reason
      positionIndex
    }
  }
}
```

**Variables**

```json
{
  "input": {
    "requestId": "example",
    "warehouseId": "00000000-0000-4000-8000-000000000001",
    "asOf": "2026-01-01T00:00:00Z",
    "items": [
      {
        "externalId": "example",
        "positions": [
          {
            "quantity": "10.00"
          }
        ]
      }
    ]
  }
}
```

**Response**

```json
{
  "data": {
    "syncStockLevels": {
      "items": [
        {
          "index": 1,
          "externalId": "example",
          "status": "APPLIED",
          "reason": "NO_EXTERNAL_REF",
          "positionIndex": 1
        }
      ]
    }
  }
}
```

Values are illustrative: replace IDs and codes with your own before you send the call.
