## Cancel conducting of an inventory document

`POST /v1/catalog-documents/:id/cancel`

Cancels conducting of an inventory document: the product stock in the warehouses returns to the values it had before conducting, and the document is no longer conducted. Call it when you need to edit a conducted document or its items.

## Parameters

| Parameter | Type | Required | Description |
|----------|-----|:-----:|---------|
| `id` (path) | number | yes | Document ID, a positive integer without leading zeros. List: [`GET /v1/catalog-documents`](./list.md) |

Send an empty object `{}` with the `Content-Type: application/json` header, or send the request with no body and without that header.

## Examples

### curl — personal key

```bash
curl -X POST "https://vibecode.bitrix24.com/v1/catalog-documents/301/cancel" \
  -H "X-Api-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{}'
```

### curl — OAuth application

```bash
curl -X POST "https://vibecode.bitrix24.com/v1/catalog-documents/301/cancel" \
  -H "X-Api-Key: YOUR_APP_KEY" \
  -H "Authorization: Bearer USER_SESSION_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{}'
```

### JavaScript — personal key

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/catalog-documents/301/cancel', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_API_KEY',
    'Content-Type': 'application/json',
  },
  body: '{}',
})

const { success, data } = await res.json()
console.log('Document status:', data.status)
```

### JavaScript — OAuth application

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/catalog-documents/301/cancel', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_APP_KEY',
    'Authorization': 'Bearer USER_SESSION_TOKEN',
    'Content-Type': 'application/json',
  },
  body: '{}',
})

const { success, data } = await res.json()
```

## Response fields

| Field | Type | Description |
|------|-----|---------|
| `success` | boolean | `true` on success |
| `data.id` | number | Document ID |
| `data.status` | string | Document status, re-read after cancellation. Always `N` in a successful response |

Other document fields — [`GET /v1/catalog-documents/:id`](./get.md). The `statusBy` and `dateStatus` fields show who last changed the status and when.

## Response example

```json
{
  "success": true,
  "data": {
    "id": 301,
    "status": "N"
  }
}
```

## Error response example

422 — the document is not conducted:

```json
{
  "success": false,
  "error": {
    "code": "BITRIX_ERROR",
    "message": "Document conduct cancellation error: The document is not conducted yet.",
    "b24Code": "0"
  }
}
```

## Errors

| HTTP | Code | Description |
|------|-----|---------|
| 400 | `INVALID_PARAMS` | `id` in the path is not a positive integer, or the request body is not empty. Error text — `id must be a positive safe integer and body must be empty` |
| 400 | `FST_ERR_CTP_EMPTY_JSON_BODY` | The `Content-Type: application/json` header is sent, but the body is empty. Send `{}` or remove the header |
| 404 | `ENTITY_NOT_FOUND` | No document with this `id`. Error text — `Catalog document not found` |
| 422 | `BITRIX_ERROR` | The document is not conducted. Error text — `Document conduct cancellation error: The document is not conducted yet.` |
| 422 | `BITRIX_ERROR` | Bitrix24 rejected the cancellation for another reason. The reason text is in `message` |
| 422 | `BITRIX_ERROR` | Bitrix24 did not confirm the cancellation. Error text — `Bitrix24 rejected the document action` |
| 422 | `BITRIX_ERROR` | The document was re-read, and its status did not become `N`. Error text — `Document action did not change status` |
| 502 | `BITRIX_UNAVAILABLE` | The portal is unavailable, or the document status could not be re-read after cancellation. In the second case the error text is `Unable to verify document status` |
| 503 | `BITRIX_TIMEOUT` | Bitrix24 did not respond in time. The cancellation may have taken place — before retrying, check `status` via [`GET /v1/catalog-documents/:id`](./get.md) |
| 403 | `BITRIX_ACCESS_DENIED` | Bitrix24 denied the key's user access to the operation |
| 403 | `WRITE_BLOCKED_READONLY_KEY` | The key works in read-only mode |
| 403 | `SCOPE_DENIED` | The API key does not have the `catalog` scope |
| 401 | `MISSING_API_KEY` | The `X-Api-Key` header is not passed |
| 401 | `INVALID_API_KEY` | The passed API key was not found |
| 401 | `TOKEN_MISSING` | The API key has no configured tokens |

Full list of common API errors — [Errors](/docs/errors).

## See also

- [Conduct a document](./conduct.md)
- [Get an inventory document](./get.md)
- [Update an inventory document](./update.md)
- [Inventory document items](/docs/entities/catalog-document-elements)
- [Warehouse stock](/docs/entities/warehouses/stock)
- [Inventory documents](/docs/entities/catalog-documents)
