---
title: "Every stock count on file, with its totals and the variance it found"
method: GET
path: "/api/v1/stocktakes/table"
tags: ["stocktakes"]
---

# Every stock count on file, with its totals and the variance it found

`GET /api/v1/stocktakes/table`

## Request

- Base URL: `https://api.app.tightly.io`
- URL: `https://api.app.tightly.io/api/v1/stocktakes/table`
- Auth: HTTP bearer

One page of counts, newest scope first, each row carrying what the count covers and what it found: `line_count` and `counted_line_count`, the `system_total` and `counted_total` over the counted lines only, and `variance_total` (which is exactly `counted_total - system_total`) with `variance_value_total` beside it.

`variance_value_total` PRICES AN UNPRICED LINE AT ZERO. A counted line on a variant with no cost on file contributes nothing to the money while contributing its units to `variance_total`, so the two totals can disagree about how much of a count is accounted for. get_stocktake_lines_table serves `unit_cost` per line, and a null there is what the money is missing.

`status` is `open` or `posted`. An open count is still being counted and its figures move; a posted one is frozen and carries `posted_at`. Filter on it with `filter_args=[{"key":"status","operation":"eq","value":"open"}]`, the only filterable key.

`search` matches the count's name. `sort_args` takes `name`, `status`, `counted_on`, `line_count`, `variance_total` or `variance_value_total`, prefixed `-` for descending. `limit` defaults to 10 and `offset` to 0; `max_size` is every count on file and `filtered_max_size` is how many the search and filters left, so a caller pages on the second.

`id` is a string on the wire and is what the by-id operations take. `location_names` is for display only. A count is scoped by location id at creation and the names are resolved on read.

Scope: `stocktakes:read`.

## Query parameters

- `search` string
- `limit` integer
- `offset` integer
- `sort_args` string
- `filter_args` string

## Headers

- `Tightly-Version` string

## Response `200`

One page of counts, with the totals each one found.

- object
  - `data` GetStocktakesTablePayload
    - `filtered_max_size` integer, required
    - `max_size` integer, required
    - `offset` integer, required
    - `rows` Stocktake[], required
      - `counted_line_count` integer, required
      - `counted_on` string, required
      - `counted_total` integer, required
      - `id` string, required
      - `line_count` integer, required
      - `location_names` string[]
      - `name` string, required
      - `posted_at` string, nullable
      - `status` 'open' | 'posted', required
      - `system_total` integer, required
      - `variance_total` integer, required
      - `variance_value_total` number, required
    - `size` integer, required
  - `message` object: severity, service and desc.

## Other responses

- `400`: `filter_args` is not JSON, names a key other than `status`, or carries a value that is not `open` or `posted`; or `limit` is over 10,000.
- `401`: No usable key: malformed, unknown, revoked, expired or stopped. One refusal covers all five, telling a caller which is which maps the surface for them. A request with no Authorization header at all is refused 400 before any key is looked for.
- `403`: The key may not reach this operation. `scope_missing` when the key does not hold Stocktakes; `organization_mismatch` when the path names an organisation that is not the key's; `ip_not_allowed` when the caller's address is outside the key's allowlist.
- `429`: The key has spent its allowance for this minute. 600 reads and 120 writes a minute, counted per key, refused calls included. `Retry-After` says how long to wait.
- `503`: The database is briefly out of reach, which is what a failover or a full connection pool looks like from outside. Wait the seconds `Retry-After` names and send the request again. A read is safe to repeat. A write is not, because the connection was lost in the middle of it, so read the object back before sending it a second time. Branch on the status rather than on `code`, which is `POSTGRES_UNAVAILABLE` from one of the two seams that raise this and `SERVICE_UNAVAILABLE` from the other.

---

[API](https://skmtc.dev/tightly/apis/tightly-api.md) · [All operations](https://skmtc.dev/tightly/apis/tightly-api/llms.txt) · [OpenAPI document](https://skmtc.dev/tightly/apis/tightly-api/revisions/199f7eb35afb?raw)
