# stockDemand query


`stockDemand` is a GraphQL query 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).

Returns a page of what confirmed orders wait for in the named warehouses, by variant, then
warehouse: per product variant and warehouse, what is `waiting`, what is `incoming` to make it
reservable, and what is `missing`. Use it with [`stockSources`](/chameleoon-max/query/stock-sources) to plan a move of the
goods that orders wait for, then write a transfer advice. Nothing is moved.

- Requires the `stockCard.read` and `transferAdvice.read` permissions.
- Only rows with something waiting are returned.
- A warehouse outside your API key's warehouse, legal-entity or country scope is left out, as
  in [`stockCards`](/chameleoon-max/query/stock-cards).
- The connection has no total count.

#### What counts as incoming

`incoming` is the remaining quantity of the `OPEN` transfer advice lines of the variant into the
warehouse that will make goods reservable there:

- Inside the warehouse: the line's target bin is pickable, of kind `STOCK` or `RECEIVING` and in
  use, and its source bin is not pickable (or not set).
- From another warehouse: the bin the goods land on -- the line's target bin, or the target
  warehouse's default bin when the line names none -- is pickable, of kind `STOCK` or
  `RECEIVING` and in use.
- In both, the line's lot, if it names one, is released and not expired where the target
  warehouse blocks expired stock.

[`binRefills`](/chameleoon-max/query/bin-refills) takes the same `incoming` off the waiting share it proposes, so a refill by
levels and a refill for orders never move the same waiting twice.

#### Excepting your own advices

`filter.exceptAdviceIds` names OPEN transfer advices that nobody has started, at most 20. Their
remaining quantity is left out of `incoming`. The rules are those of [`binRefills`](/chameleoon-max/query/bin-refills): an
advice somebody has started returns `VALIDATION` at `exceptAdviceIds` with `extensions.reason`
`ADVICE_STARTED`, and any other id changes nothing.

Pass exactly one of `first` or `last`, from 1 to 250. `first` (with `after`) pages forward;
`last` (with `before`) pages backward. `last` alone returns the last page. Every edge carries
its own cursor.

A page costs 2 + first (or last) × the cost of one node.

## Arguments

- `filter`: [`StockDemandFilter!`](/chameleoon-max/type/stock-demand-filter) · required
- `first`: `Int`
- `after`: `String`
- `last`: `Int`
- `before`: `String`

## Returns

[`StockDemandConnection!`](/chameleoon-max/type/stock-demand-connection): a page of [`StockDemand`](/chameleoon-max/type/stock-demand).

## Example

**Query**

```graphql
query stockDemand($filter: StockDemandFilter!, $first: Int) {
  stockDemand(filter: $filter, first: $first) {
    edges {
      cursor
    }
    nodes {
      variantId
      warehouseId
      waiting
      incoming
      missing
    }
    pageInfo {
      hasNextPage
      hasPreviousPage
      startCursor
      endCursor
    }
  }
}
```

**Variables**

```json
{
  "filter": {
    "warehouseIds": [
      "00000000-0000-4000-8000-000000000001"
    ]
  },
  "first": 10
}
```

**Response**

```json
{
  "data": {
    "stockDemand": {
      "edges": [
        {
          "cursor": "example"
        }
      ],
      "nodes": [
        {
          "variantId": "00000000-0000-4000-8000-000000000001",
          "warehouseId": "00000000-0000-4000-8000-000000000001",
          "waiting": "10.00",
          "incoming": "10.00",
          "missing": "10.00"
        }
      ],
      "pageInfo": {
        "hasNextPage": true,
        "hasPreviousPage": true,
        "startCursor": "example",
        "endCursor": "example"
      }
    }
  }
}
```

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