---
title: "Apply counted quantities to an open count from an uploaded CSV or Excel file"
method: POST
path: "/api/v1/stocktakes/{stocktake_id}/import"
tags: ["stocktakes"]
---

# Apply counted quantities to an open count from an uploaded CSV or Excel file

`POST /api/v1/stocktakes/{stocktake_id}/import`

## Request

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

Applies a whole file of counts to an open count. The body is `s3_key`, a file already uploaded through the shared presigned-URL flow, and `mappings`, a `{our_field: their_header}` object in the same shape `GET /files/mappings` returns. `sku` and `counted_quantity` are both required in the mapping; `location` is optional.

Rows match the count's lines on SKU, case-insensitively and ignoring surrounding spaces, and on location name as well when a `location` column is mapped. A SKU held at several locations in the count's scope with no location column is reported in `unmatched_skus` rather than guessed at: putting a count on the wrong shelf is worse than not putting it anywhere.

The response is a summary, not the lines: `updated` is how many lines took a count, `skipped` is how many rows were readable but changed nothing, and `unmatched_skus` lists what the file names and the count ignored, a SKU outside the scope, or an ambiguous one. A quantity that is not a number is skipped, not zeroed.

Refused 400 once the count is posted. To set a handful of lines without a file, use update_stocktake_counts.

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

## Path parameters

- `stocktake_id` integer, required

## Headers

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

## Request body

- ImportStocktakeCountsRequest
  - `mappings` object, required
  - `s3_key` string, required

## Response `200`

What the file changed, and what it names that the count does not cover.

- object
  - `data` ImportStocktakeCountsPayload
    - `skipped` integer, required
    - `unmatched_skus` string[]
    - `updated` integer, required
  - `message` object: severity, service and desc.

## Other responses

- `400`: A blank `s3_key`; a mapping missing the SKU or the counted-quantity column; a file that is empty or cannot be read; or the count has already been posted.
- `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)
