# Open the draft document that bills it

`POST /businesses/{bid}/appointments/{id}/document`

Requires the `businesses` scope.

A DRAFT with the customer and one line (the title and the day, at the appointment's price), filed under `externalRef: appointment:<id>`. Default type: an invoice-receipt (320), a receipt (400) for a עוסק פטור. A second call returns the open draft or the issued document. Issuing is the ordinary issue call. Needs documents on top of businesses.

## Path parameters

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

## Body (optional)

| Field | Type | | Description |
|---|---|---|---|
| `docType` | integer |  | Any type the business may issue. |
| `payments` | array of Payment |  |  |
| `documentDate` | string |  | Default: today. |

## 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. |

Errors: `400`, `401`, `403`, `404`, `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/appointments/$DOC_ID/document" \
  -H "X-Api-Key: $KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "payments": [
      {
        "method": 3,
        "amount": 120000
      }
    ]
  }'
```
### Node

```node
const res = await fetch(`${BASE}/businesses/${BID}/appointments/${DOC_ID}/document`, {
  method: 'POST',
  headers: {
    'X-Api-Key': KEY,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    "payments": [
      {
        "method": 3,
        "amount": 120000
      }
    ]
  }),
})
const data = await res.json()
if (!data.ok) throw new Error(data.reason)
```
### Python

```python
import requests
res = requests.post(
    f"{BASE}/businesses/{BID}/appointments/{DOC_ID}/document",
    headers={"X-Api-Key": KEY},
    json={
      "payments": [
        {
          "method": 3,
          "amount": 120000
        }
      ]
    },
)
data = res.json()
```