# Run a plan now

`POST /businesses/{bid}/recurring/{id}/run`

Requires the `documents` scope.

Produces today's document (a draft, or an issued document with `autoIssue`) without moving the schedule. Idempotent for the day: a second call the same day finds the document the first one made. `outcome` is `draft`, `issued` or `failed` (with `error`).

## Path parameters

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

## Response

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

| Field | Type | | Description |
|---|---|---|---|
| `ok` | boolean | **required** |  |
| `outcome` | string | **required** |  One of: `draft`, `issued`, `failed`. |
| `document` | Document |  | A draft is freely mutable. An issued document is immutable forever, blocked at the database engine, not merely in application code. |
| `plan` | RecurringPlan | **required** | A template the scheduler turns into a draft (or an issued document, with `autoIssue`) every interval. Not a document: freely editable and deletable. |
| `error` | string |  |  |

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/recurring/$DOC_ID/run" \
  -H "X-Api-Key: $KEY"
```
### Node

```node
const res = await fetch(`${BASE}/businesses/${BID}/recurring/${DOC_ID}/run`, {
  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}/recurring/{DOC_ID}/run",
    headers={"X-Api-Key": KEY},
)
data = res.json()
```