---
title: "Fill a form from values or source documents"
---

> Documentation Index
> Fetch the complete documentation index at: https://docs.cloudraker.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Fill a form from values or source documents

Path: CloudRaker Paperwork API › Spaces

`POST /v1/spaces/{spaceId}/fill`

Fills a form PDF and returns the completed file. Send exactly one of `values` or `files`:

- `values` — the field values to write, keyed by field name. Deterministic: no drafting pass, no model call.
- `files` — source documents the field values are drafted from.

**Pick the form** with `template`, either shape:

- `{ "id": "…" }` — a saved [template](https://docs.cloudraker.com/paperwork/api/templates/get-template), or any file you own.
- `{ "url": "…" }` — fetched fresh for this run and purged with it.

`template` is optional when `action` names a saved config that carries one; sending it inline still wins.

**Shape the output** with `output`: `flattened` (default) bakes the values in, `editable` leaves the form fillable.

```json
{
  "files": [{ "id": "a04d6597-4e34-4a99-94ea-964c289a4c68" }],
  "template": { "id": "23e0a865-0be9-45b1-a491-f1b6bd58a31a" }
}
```

### Waiting for the result

Sync by default: the call holds open until the run finishes, up to `?wait=` seconds (default `60`, max `120`, `0` returns immediately).

| Outcome | Response |
| --- | --- |
| Finished inside the window | `200` with the full run |
| Still running at the cap | `202` with `{object, id, status, statusUrl}` |

> **Note:** The `202` is a graceful degrade, never an error — poll [the run](https://docs.cloudraker.com/paperwork/api/runs/get-run) or wait for a [webhook](https://docs.cloudraker.com/paperwork/api/webhook-endpoints/create-webhook-endpoint). Replaying an `idempotency-key` returns the original run alongside an `idempotent-replay: true` response header.

**Learn more:** [Form filling guide](https://docs.cloudraker.com/paperwork/capabilities/fill)

## Authentication

- `bearerAuth`, http, header `Authorization`

## Path parameters

- `spaceId` (`spaceFill.path.spaceId`; string, required)

## Query parameters

- `wait` (`spaceFill.query.wait`; integer, optional) — How many seconds to hold the request open waiting for the run to finish. Finishing inside the window returns `200` with the full run; running past it returns `202` with a `statusUrl` to poll. Send `0` to skip waiting entirely and always get the `202`.
  - min 0; max 120; default `60`

## Request body

_Required._

- `template` (`spaceFill.template`; any of, optional) — The blank form to fill, given one of two ways. - `{ "id": "…" }` — a saved template from `POST /v1/templates`, or any file you own. - `{ "url": "…", "name"?: "…" }` — fetched for this run only and purged with it. Optional when `action` names a saved config that carries one — sending it inline still wins.
  - any of:
    - `object`
      - `id` (`spaceFill.template.1.id`; string, required)
        - minLength 1
    - `object`
      - `url` (`spaceFill.template.2.url`; string, required)
        - format `uri`
      - `name` (`spaceFill.template.2.name`; string, optional)
        - minLength 1
- `instructions` (`spaceFill.instructions`; string, optional) — Free-form guidance for the drafting pass — which source document wins a conflict, how to format dates, which fields to leave blank.
  - maxLength 4000
- `output` (`spaceFill.output`; string, optional) — What the produced PDF looks like. `flattened` (the default) bakes the values in so nothing can be changed; `editable` leaves the form fillable.
  - one of `"flattened"`, `"editable"`
- `action` (`spaceFill.action`; string, optional) — A saved fill action to run, by id or slug. Config you send inline is merged over the saved config.
  - minLength 1
- `files` (`spaceFill.files`; array<any of>, optional) — The source documents the field values are drafted from, up to 100. Send this or `values`, never both.
  - any of:
    - `object`
      - `url` (`spaceFill.files.1.url`; string, required)
        - format `uri`
      - `name` (`spaceFill.files.1.name`; string, optional)
        - minLength 1
      - `processing` (`spaceFill.files.1.processing`; string, optional)
        - one of `"auto"`, `"ocr"`, `"simple"`, `"transcribe"`, `"transcribe_diarize"`
    - `object`
      - `id` (`spaceFill.files.2.id`; string, required)
        - minLength 1
      - `ephemeral` (`spaceFill.files.2.ephemeral`; boolean, optional) — Purge this file with the run (TTL expiry or `DELETE /v1/runs/{id}`), unless you `keep` the run. API workspace only: ignored under `/v1/spaces/{spaceId}/…`.
- `values` (`spaceFill.values`; map<unknown>, optional) — The field values to write, keyed by field name — deterministic, no drafting pass. Send this or `files`, never both.
- `metadata` (`spaceFill.metadata`; map<unknown>, optional) — Arbitrary JSON you attach to the run and get back on every read of it. Use it to carry your own identifiers — an order number, a customer id — so a webhook or a polled run reconciles without a lookup table. Capped at 10 KB serialized.
- `webhook` (`spaceFill.webhook`; any of, optional) — Where to deliver this run's events, given one of two ways. - `{ "url": "…" }` — a one-off https endpoint for this run only. - `{ "id": "whe_…" }` — a saved endpoint from `POST /v1/webhooks`. Runs hold the reference, so pausing or re-pointing that endpoint applies to this run too. Deliveries are at-least-once and signed — dedupe on `eventId` and verify against `GET /v1/webhooks/jwks.json`.
  - any of:
    - `object`
      - `url` (`spaceFill.webhook.1.url`; string, required)
        - format `uri`
    - `object`
      - `id` (`spaceFill.webhook.2.id`; string, required)
        - minLength 1
- `ttl` (`spaceFill.ttl`; integer, optional) — How long, in seconds, to keep this run and its files before purging them automatically. The maximum is 604800 (7 days). The deadline comes back as `expiresAt` on every read of the run. Call `POST /v1/runs/{id}/keep` before then to clear the TTL and move the results into a space permanently. E-signature runs are exempt — an envelope waits for its signers however long that takes.
  - min 1; max 604800; default `86400`

## Example request

```json
{
  "template": {
    "id": "string"
  },
  "instructions": "string",
  "output": "flattened",
  "action": "string",
  "files": [
    {
      "url": "http://example.com",
      "name": "string",
      "processing": "auto"
    }
  ],
  "values": {
    "property1": null,
    "property2": null
  },
  "metadata": {
    "property1": null,
    "property2": null
  },
  "webhook": {
    "url": "http://example.com"
  },
  "ttl": 86400
}
```

## Code samples

### cURL

```bash
curl --request POST \
  --url 'https://api.cloudraker.com/v1/spaces/<spaceId>/fill' \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "template": {
    "id": "string"
  },
  "instructions": "string",
  "output": "flattened",
  "action": "string",
  "files": [
    {
      "url": "http://example.com",
      "name": "string",
      "processing": "auto"
    }
  ],
  "values": {
    "property1": null,
    "property2": null
  },
  "metadata": {
    "property1": null,
    "property2": null
  },
  "webhook": {
    "url": "http://example.com"
  },
  "ttl": 86400
}
'
```

### TypeScript

```typescript
const url = 'https://api.cloudraker.com/v1/spaces/<spaceId>/fill';
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json', Authorization: 'Bearer <token>'},
  body: JSON.stringify({
    template: {id: 'string'},
    instructions: 'string',
    output: 'flattened',
    action: 'string',
    files: [{url: 'http://example.com', name: 'string', processing: 'auto'}],
    values: {property1: null, property2: null},
    metadata: {property1: null, property2: null},
    webhook: {url: 'http://example.com'},
    ttl: 86400
  })
};

fetch(url, options)
  .then(res => res.json())
  .then(json => console.log(json))
  .catch(err => console.error(err));
```

### Python

```python
import requests

url = "https://api.cloudraker.com/v1/spaces/<spaceId>/fill"

payload = {
    "template": { "id": "string" },
    "instructions": "string",
    "output": "flattened",
    "action": "string",
    "files": [
        {
            "url": "http://example.com",
            "name": "string",
            "processing": "auto"
        }
    ],
    "values": {
        "property1": None,
        "property2": None
    },
    "metadata": {
        "property1": None,
        "property2": None
    },
    "webhook": { "url": "http://example.com" },
    "ttl": 86400
}
headers = {
    "Content-Type": "application/json",
    "Authorization": "Bearer <token>"
}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
```

## Responses

### 200

The finished run.

#### Example

```json
{
  "object": "fill_run",
  "id": "string",
  "status": "queued",
  "expiresAt": "string",
  "statusUrl": "string",
  "files": [
    {
      "id": "string",
      "name": "string",
      "status": "string",
      "error": "string"
    }
  ],
  "file": {
    "id": "string",
    "name": "string",
    "status": "string",
    "error": "string"
  },
  "error": {
    "code": "string",
    "message": "string"
  },
  "metadata": {
    "property1": null,
    "property2": null
  },
  "output": {
    "file": {
      "id": "string",
      "name": "string",
      "url": "string"
    },
    "files": [
      {
        "id": "string",
        "name": "string",
        "url": "string"
      }
    ],
    "fields": {
      "property1": null,
      "property2": null
    }
  }
}
```

- `object` (`spaceFill.response.200.object`; string, required)
- `id` (`spaceFill.response.200.id`; string, required)
- `status` (`spaceFill.response.200.status`; string, required) — Where the run is in its life. | Status | Meaning | | --- | --- | | `queued` | Accepted, not started | | `processing` | Work in flight | | `needs_input` | Waiting for an external action, such as an e-signature | | `processed` | Finished; `output` is populated | | `failed` | Finished unsuccessfully | | `cancelled` | Stopped on request | | `expired` | TTL elapsed and the data was purged | The last four are terminal.
  - one of `"queued"`, `"processing"`, `"processed"`, `"failed"`, `"cancelled"`, `"expired"`, `"needs_input"`
- `expiresAt` (`spaceFill.response.200.expiresAt`; string | null, required)
- `statusUrl` (`spaceFill.response.200.statusUrl`; string, required)
- `files` (`spaceFill.response.200.files`; array<object>, required)
  - `id` (`spaceFill.response.200.files.id`; string, required)
  - `name` (`spaceFill.response.200.files.name`; string, required)
  - `status` (`spaceFill.response.200.files.status`; string, required)
  - `error` (`spaceFill.response.200.files.error`; string, optional)
- `file` (`spaceFill.response.200.file`; object, optional)
  - `id` (`spaceFill.response.200.file.id`; string, required)
  - `name` (`spaceFill.response.200.file.name`; string, required)
  - `status` (`spaceFill.response.200.file.status`; string, required)
  - `error` (`spaceFill.response.200.file.error`; string, optional)
- `error` (`spaceFill.response.200.error`; object, optional) — Why the run failed. Present whenever `status` is `failed`, and only then. `code` is the stable, snake_case reason (`input_unavailable`, `parse_failed`, …); `message` is the human-readable detail. Per-file and per-step failures are also reported in `files[].error` and, for a pipeline, `steps[].error`.
  - `code` (`spaceFill.response.200.error.code`; string, required)
  - `message` (`spaceFill.response.200.error.message`; string, required)
- `metadata` (`spaceFill.response.200.metadata`; map<unknown>, optional)
- `output` (`spaceFill.response.200.output`; object, optional) — The completed form. Present once `status` is `processed`. `file` is the filled PDF with a signed download link; `fields` reports the values that were written into it, keyed by field name.
  - `files` (`spaceFill.response.200.output.files`; array<object>, required)
    - `id` (`spaceFill.response.200.output.files.id`; string, required)
    - `name` (`spaceFill.response.200.output.files.name`; string, required)
    - `url` (`spaceFill.response.200.output.files.url`; string, optional)
  - `file` (`spaceFill.response.200.output.file`; object, optional)
    - `id` (`spaceFill.response.200.output.file.id`; string, required)
    - `name` (`spaceFill.response.200.output.file.name`; string, required)
    - `url` (`spaceFill.response.200.output.file.url`; string, optional)
  - `fields` (`spaceFill.response.200.output.fields`; map<unknown>, optional)

### 202

Accepted — still running, or awaiting human input.

#### Example

```json
{
  "object": "string",
  "id": "string",
  "status": "queued",
  "statusUrl": "string",
  "envelopeUrl": "string"
}
```

- `object` (`spaceFill.response.202.object`; string, required)
- `id` (`spaceFill.response.202.id`; string, required)
- `status` (`spaceFill.response.202.status`; string, required) — Where the run is in its life. | Status | Meaning | | --- | --- | | `queued` | Accepted, not started | | `processing` | Work in flight | | `needs_input` | Waiting for an external action, such as an e-signature | | `processed` | Finished; `output` is populated | | `failed` | Finished unsuccessfully | | `cancelled` | Stopped on request | | `expired` | TTL elapsed and the data was purged | The last four are terminal.
  - one of `"queued"`, `"processing"`, `"processed"`, `"failed"`, `"cancelled"`, `"expired"`, `"needs_input"`
- `statusUrl` (`spaceFill.response.202.statusUrl`; string, required)
- `envelopeUrl` (`spaceFill.response.202.envelopeUrl`; string, optional)

### 400

Invalid request (`invalid_request` / `invalid_schema`).

### 422

Unusable input file or webhook endpoint.

### 429

Rate limited. The `/v1` API allows at least **67 requests per minute per organization** (about 1,000 requests per 15 minutes) — a guaranteed floor, enforced per edge location, so a geographically spread caller may get more. Wait for the `Retry-After` interval and retry — the error is `retryable`.

#### Example

```json
{
  "code": "rate_limited",
  "message": "string",
  "retryable": true,
  "requestId": "string",
  "docUrl": "string"
}
```

- `code` (`spaceFill.response.429.code`; string, required)
  - one of `"rate_limited"`
- `message` (`spaceFill.response.429.message`; string, required)
- `retryable` (`spaceFill.response.429.retryable`; boolean, required)
  - one of `true`
- `requestId` (`spaceFill.response.429.requestId`; string, required)
- `docUrl` (`spaceFill.response.429.docUrl`; string, optional)


Source: https://docs.cloudraker.com/paperwork/api/spaces/space-fill/index.md
