# Book an appointment

`POST /businesses/{bid}/appointments`

Requires the `businesses` scope.

Send an `Idempotency-Key`: the same key books once and answers the appointment already booked with `deduped: true`. Overlaps and hours outside the working hours are allowed.

## Path parameters

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

## Headers

| Name | Type | | Description |
|---|---|---|---|
| `Idempotency-Key` | string |  | Your own stable id for this call. A retry returns the same row with `deduped: true` instead of creating a duplicate. Interchangeable with `externalRef` in the body. |

## Body

| Field | Type | | Description |
|---|---|---|---|
| `partyId` | string |  | A saved party (find or create it first). Optional: a block of time needs no customer. |
| `serviceId` | string |  |  |
| `title` | string |  | ≤120 chars. Default: the service, else the customer, else "פגישה". |
| `date` | string |  | YYYY-MM-DD, the Israel calendar day. |
| `start` | string |  | HH:MM, local Israel time. |
| `minutes` | integer |  | 5..1440. Default: the service, else the calendar's defaultMinutes. |
| `priceAgorot` | integer |  |  Integer agorot (₪1 = 100). |
| `priceMode` | string |  |  One of: `gross`, `net`. Default `gross`. |
| `location` | string |  | Default: the calendar's first location. One of: `business`, `customer`, `remote`. |
| `address` | string |  | ≤300 chars. |
| `meetingUrl` | string |  | An http(s) address. |
| `notes` | string |  | ≤2000 chars. |

## Response

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

| Field | Type | | Description |
|---|---|---|---|
| `ok` | boolean | **required** |  |
| `appointment` | Appointment | **required** | An appointment on the business's calendar. Not a document: freely edited and deleted, in no export. |

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/appointments" \
  -H "X-Api-Key: $KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "priceMode": "gross"
  }'
```
### Node

```node
const res = await fetch(`${BASE}/businesses/${BID}/appointments`, {
  method: 'POST',
  headers: {
    'X-Api-Key': KEY,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    "priceMode": "gross"
  }),
})
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",
    headers={"X-Api-Key": KEY},
    json={
      "priceMode": "gross"
    },
)
data = res.json()
```