# Record a payment of an imported debt

`POST /businesses/{bid}/legacy-documents/{id}/settle`

Requires the `documents` scope.

Names an issued BillOS document as paying (a receipt, on a 305) or replacing (a 305 or 320, on a 300; a receipt for a עוסק פטור) an archived document still owed. A receipt pays its sum, never more than is left; a replacement closes it whole. The same document twice changes nothing. Usually sent with the issue itself, as `settlesLegacy`.

## Path parameters

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

## Body

| Field | Type | | Description |
|---|---|---|---|
| `documentId` | string | **required** | The issued BillOS document. |

## Response

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

| Field | Type | | Description |
|---|---|---|---|
| `ok` | boolean | **required** |  |
| `document` | LegacyDocument | **required** | A document issued by the software the business used before BillOS: its metadata as that system printed it, and the original file. Not a BillOS document: no number from any series, no signature, absent from every export and report. |
| `deduped` | boolean |  |  |

Errors: `400`, `401`, `403`, `404`, `409`, `429`. Every failure answers `{ "error", "reason", "hint", "param", "doc_url", "retryable", "request_id" }`: branch on `reason`, and read `hint` for what to change (https://docs.billos.co.il/errors.md).

## Examples

### cURL

```bash
curl -X POST "$BASE/businesses/$BID/legacy-documents/$DOC_ID/settle" \
  -H "X-Api-Key: $KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "documentId": "string"
  }'
```
### Node

```node
const res = await fetch(`${BASE}/businesses/${BID}/legacy-documents/${DOC_ID}/settle`, {
  method: 'POST',
  headers: {
    'X-Api-Key': KEY,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    "documentId": "string"
  }),
})
const data = await res.json()
if (!data.ok) throw new Error(data.reason)
```
### Python

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