# binRefills query


`binRefills` 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 the picking bins' levels in the named warehouses, by variant, bin code, then
bin id. A level is a product variant's minimum and maximum on a picking bin (pickable, kind
`STOCK` or `RECEIVING`). Each comes with what to move to the bin from the warehouse's reserve
bins, and from which rows of [`stockQuants`](/chameleoon-max/query/stock-quants). Use it to plan refills of the pick face,
then write a transfer advice. Nothing is moved.

- Requires the `stockCard.read` and `position.read` permissions.
- A source's `lot` also requires the `lot.read` permission.
- 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.

#### How the refill is worked out

- `need`: when `onLocation` + `coming` is under the minimum, the maximum (or else the minimum)
  minus `onLocation` and `coming`. The variant's level bin that holds least (`onLocation` +
  `coming`, then bin code, then bin id) also needs the variant's `waiting` in the warehouse
  ([`StockFigures`](/chameleoon-max/type/stock-figures)), less its `incoming` there as [`stockDemand`](/chameleoon-max/query/stock-demand) counts it. A
  bin's need is the larger of the two.
- Free reserve: for each row on a reserve bin (not pickable, kind `STOCK` or `RECEIVING`, in use,
  its lot released and not expired where the warehouse blocks expired stock), its quantity less
  what is reserved on that bin and lot.
- `refill`: a variant's bins in one warehouse are served in that same order, each taking the
  lesser of its need and the free reserve the earlier bins left. It is exactly the sum of
  `sources`.
- `sources`: the refill split over the free reserve, first expiry first (an expired lot last
  where the warehouse only warns), then the larger free quantity first, then bin code, bin id
  and lot. At most 20 per bin: a 21st row is not used, and the refill stops there.

The split is worked out over all of a variant's bins in a warehouse before any status filter or
page is applied, so every page, and any set of pages, shows the split one read of everything
shows.

#### A status filter that few bins match

One page looks at no more than 500 variants. When it stops there, the page may be short, or
even empty, and still has `hasNextPage` (`hasPreviousPage` with `last`) `true`, with its
`endCursor` (`startCursor`) at the last variant it looked at. Keep paging until it is `false`.

#### Excepting your own advices

`filter.exceptAdviceIds` names OPEN transfer advices that nobody has started, at most 20. The
answer reads as if they were not there: their remaining quantity is not `coming`, and what they
hold on reserve bins is free again, so the same rows can be named as sources again. A workflow
that plans again uses it to see the stock without the transfer advice it wrote last time.

- It requires the `transferAdvice.read` permission when it is not empty. Without it, the query
  returns `FORBIDDEN_ROLE` with `extensions.field` `exceptAdviceIds`.
- Any OPEN transfer advice your API key may read can be named, whoever wrote it.
- An advice somebody has started (a transfer links it) returns `VALIDATION` at
  `exceptAdviceIds` with `extensions.reason` `ADVICE_STARTED`.
- Any other id (an advice of another status, outside your scope, or unknown) 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`: [`BinRefillFilter!`](/chameleoon-max/type/bin-refill-filter) · required
- `first`: `Int`
- `after`: `String`
- `last`: `Int`
- `before`: `String`

## Returns

[`BinRefillConnection!`](/chameleoon-max/type/bin-refill-connection): a page of [`BinRefill`](/chameleoon-max/type/bin-refill).

## Example

**Query**

```graphql
query binRefills($filter: BinRefillFilter!, $first: Int) {
  binRefills(filter: $filter, first: $first) {
    edges {
      cursor
    }
    nodes {
      variantId
      warehouseId
      minQuantity
      maxQuantity
      onLocation
      coming
    }
    pageInfo {
      hasNextPage
      hasPreviousPage
      startCursor
      endCursor
    }
  }
}
```

**Variables**

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

**Response**

```json
{
  "data": {
    "binRefills": {
      "edges": [
        {
          "cursor": "example"
        }
      ],
      "nodes": [
        {
          "variantId": "00000000-0000-4000-8000-000000000001",
          "warehouseId": "00000000-0000-4000-8000-000000000001",
          "minQuantity": "10.00",
          "maxQuantity": "10.00",
          "onLocation": "10.00",
          "coming": "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.
