---
title: "Set counted quantities on the lines of an open count"
method: PATCH
path: "/api/v1/stocktakes/{stocktake_id}/counts"
tags: ["stocktakes"]
---

# Set counted quantities on the lines of an open count

`PATCH /api/v1/stocktakes/{stocktake_id}/counts`

## Request

- Base URL: `https://api.app.tightly.io`
- URL: `https://api.app.tightly.io/api/v1/stocktakes/{stocktake_id}/counts`
- Auth: HTTP bearer

Writes counted quantities onto lines of an open count. The body is `counts`, a non-empty array of `{variant_id, location_id, counted_quantity}`; the pair addresses the line, so a variant counted at two locations is two entries.

A `counted_quantity` of null clears a line back to uncounted, which is not the same as counting zero: a zero is a reading that says the shelf is empty, and a null says nobody has looked. A negative quantity is refused 400.

Partial by design, send only the lines that were counted, as often as needed, and the rest stay as they were. Repeating a pair inside one body keeps the last entry rather than refusing, which is what a grid posting edits in order expects. A pair that is not in the count's scope is ignored rather than created: the scope is fixed when the count is opened.

Refused 400 once the count is posted. A posted count is frozen, and a correction is a new count. Answers 204 with no body; read the count back with get_stocktake for the new totals. To apply a whole file of counts instead of naming lines, use import_stocktake_counts.

Scope: `stocktakes:write`, which includes `stocktakes:read`.

## Path parameters

- `stocktake_id` integer, required

## Headers

- `Tightly-Version` string
- `Idempotency-Key` string

## Request body

- UpdateStocktakeCountsRequest
  - `counts` StocktakeCountEntry[]
    - `counted_quantity` integer, nullable
    - `location_id` string, required
    - `variant_id` string, required

## Response `204`

The counts were applied. No body; read the count back for its new totals.

## Other responses

- `400`: An empty `counts` array, a negative `counted_quantity`, or the count has already been posted, "This count has already been posted and can no longer be changed".
- `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 holds Stocktakes for reading only, or not at all; `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.
- `404`: No count with this id in this organisation.
- `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)
