---
title: "Discard an open count and every line in it"
method: DELETE
path: "/api/v1/stocktakes/{stocktake_id}"
tags: ["stocktakes"]
---

# Discard an open count and every line in it

`DELETE /api/v1/stocktakes/{stocktake_id}`

## Request

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

Deletes an open count and its lines outright. Takes no body, and answers 204 with none.

Only an open count can be discarded. A posted count is refused 400. It is a record of what a warehouse found on a date, and deleting it would remove the evidence behind every variance figure measured from it. To correct a posted count, open a new one.

Nothing about stock changes either way: an open count has never moved a level, so discarding it leaves the shelf exactly as it was.

This is not the way to close a count. post_stocktake records what was found; this throws it away, and a count discarded by mistake has to be created and counted again from nothing.

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

## Path parameters

- `stocktake_id` integer, required

## Headers

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

## Response `204`

The count and its lines are gone. No body.

## Other responses

- `400`: 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)
