# Issue a document

`POST /businesses/{bid}/documents/{id}/issue`

Requires the `documents` scope.

The point of no return. Assigns the next gapless number, freezes a full snapshot, renders the PDF and signs it.

Totals are recomputed server-side from the frozen lines, so what comes back is authoritative. Issuing twice is safe and returns the same document with `deduped: true`. If rendering hiccups the document is still legally issued and `prints` answers `pdf_pending` until a background retry finishes; numbering never rolls back.

## Path parameters

| Name | Type | | Description |
|---|---|---|---|
| `bid` | string | **required** | Business id, from `POST /businesses`. |
| `id` | string | **required** | Document id. |

## Body (optional)

| Field | Type | | Description |
|---|---|---|---|
| `branding` | Branding |  | Appearance of the rendered PDF. Stored once per business; a logo is stored as a file and referenced by hash, never re-frozen into each document. |

## Response

`201`: `{ "ok": true, … }`

| Field | Type | | Description |
|---|---|---|---|
| `ok` | boolean | **required** |  |
| `document` | Document | **required** | A draft is freely mutable. An issued document is immutable forever, blocked at the database engine, not merely in application code. |
| `deduped` | boolean |  |  |

Errors: `400`, `401`, `403`, `404`, `409`, `422`, `429`. Every failure answers `{ "error": …, "reason": … }`. Branch on `reason`.

## Examples

### cURL

```bash
curl -X POST "$BASE/businesses/$BID/documents/$DOC_ID/issue" \
  -H "X-Api-Key: $KEY"
```
### Node

```node
const res = await fetch(`${BASE}/businesses/${BID}/documents/${DOC_ID}/issue`, {
  method: 'POST',
  headers: {
    'X-Api-Key': KEY,
  },
})
const data = await res.json()
if (!data.ok) throw new Error(data.reason)
```
### Python

```python
import requests
res = requests.post(
    f"{BASE}/businesses/{BID}/documents/{DOC_ID}/issue",
    headers={"X-Api-Key": KEY},
)
data = res.json()
```