---
title: "Compose many documents from one template"
---

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

# Compose many documents from one template

Path: CloudRaker Paperwork API › Spaces

`POST /v1/spaces/{spaceId}/compose/batch`

Renders the same template once per item — a run of invoices, contracts or letters from one call.

Every item's `data` is validated first. If ANY item fails, nothing renders and the call answers `422` with an `errors[]` naming the failing item indexes and instance paths: a half-finished batch is worse than none.

```json
{
  "template": "invoice",
  "items": [
    { "name": "acme-0042", "data": { "customer": "Acme", "total": 1240 } },
    { "name": "globex-0043", "data": { "customer": "Globex", "total": 990 } }
  ]
}
```

`output` decides what comes back:

- `files` (the default) stores each PDF and returns the list. An item's `name` names its file (`<name>.pdf`); without one the files are numbered from the template slug.
- `zip` stores ONE archive holding every PDF and returns that single file.

A `name` must be a bare file name — no `/`, no `\`, no `..`, no leading dot — and two items may not end up with the same file name.

**Learn more:** [Compose](https://docs.cloudraker.com/paperwork/capabilities/compose)

## Authentication

- `bearerAuth`, http, header `Authorization`

## Path parameters

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

## Request body

_Required._

- `template` (`spaceComposeBatch.template`; string, required)
  - minLength 1; example `"invoice"`
- `items` (`spaceComposeBatch.items`; array<object>, required)
  - `data` (`spaceComposeBatch.items.data`; map<unknown>, required)
  - `name` (`spaceComposeBatch.items.name`; string, optional)
    - minLength 1; maxLength 200; example `"acme-0042"`
- `output` (`spaceComposeBatch.output`; string, optional)
  - one of `"files"`, `"zip"`

## Example request

```json
{
  "template": "invoice",
  "items": [
    {
      "data": {
        "property1": null,
        "property2": null
      },
      "name": "acme-0042"
    },
    {
      "data": {
        "property1": null,
        "property2": null
      },
      "name": "acme-0042"
    }
  ],
  "output": "files"
}
```

## Code samples

### cURL

```bash
curl --request POST \
  --url 'https://api.cloudraker.com/v1/spaces/<spaceId>/compose/batch' \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "template": "invoice",
  "items": [
    {
      "data": {
        "property1": null,
        "property2": null
      },
      "name": "acme-0042"
    },
    {
      "data": {
        "property1": null,
        "property2": null
      },
      "name": "acme-0042"
    }
  ],
  "output": "files"
}
'
```

### TypeScript

```typescript
const url = 'https://api.cloudraker.com/v1/spaces/<spaceId>/compose/batch';
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json', Authorization: 'Bearer <token>'},
  body: JSON.stringify({
    template: 'invoice',
    items: [
      {data: {property1: null, property2: null}, name: 'acme-0042'},
      {data: {property1: null, property2: null}, name: 'acme-0042'}
    ],
    output: 'files'
  })
};

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>/compose/batch"

payload = {
    "template": "invoice",
    "items": [
        {
            "data": {
                "property1": None,
                "property2": None
            },
            "name": "acme-0042"
        },
        {
            "data": {
                "property1": None,
                "property2": None
            },
            "name": "acme-0042"
        }
    ],
    "output": "files"
}
headers = {
    "Content-Type": "application/json",
    "Authorization": "Bearer <token>"
}

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

print(response.text)
```

## Responses

### 201

The composed files, or the single zip file.

#### Example

```json
{
  "object": "list",
  "data": [
    {
      "object": "file",
      "id": "string",
      "name": "string",
      "mimeType": "string",
      "status": "uploading",
      "createdAt": "string",
      "parentFileId": "string",
      "metadata": {
        "property1": "string",
        "property2": "string"
      },
      "error": "string",
      "uploadUrl": "string",
      "uploadExpiresAt": "string",
      "urls": {
        "content": "string",
        "markdown": "string",
        "json": "string"
      },
      "composeTemplate": "string",
      "templateHash": "string",
      "composedAt": "string"
    }
  ]
}
```

- `object` (`spaceComposeBatch.response.201.object`; string, required)
- `data` (`spaceComposeBatch.response.201.data`; array<object>, required)
  - `object` (`spaceComposeBatch.response.201.data.object`; string, required)
  - `id` (`spaceComposeBatch.response.201.data.id`; string, required)
  - `name` (`spaceComposeBatch.response.201.data.name`; string, required)
  - `mimeType` (`spaceComposeBatch.response.201.data.mimeType`; string, required)
  - `status` (`spaceComposeBatch.response.201.data.status`; string, required)
    - one of `"uploading"`, `"processing"`, `"ready"`, `"failed"`
  - `createdAt` (`spaceComposeBatch.response.201.data.createdAt`; string, required)
  - `parentFileId` (`spaceComposeBatch.response.201.data.parentFileId`; string, optional)
  - `metadata` (`spaceComposeBatch.response.201.data.metadata`; map<string>, optional)
  - `error` (`spaceComposeBatch.response.201.data.error`; string, optional)
  - `uploadUrl` (`spaceComposeBatch.response.201.data.uploadUrl`; string, optional)
  - `uploadExpiresAt` (`spaceComposeBatch.response.201.data.uploadExpiresAt`; string, optional)
  - `urls` (`spaceComposeBatch.response.201.data.urls`; object, optional)
    - `content` (`spaceComposeBatch.response.201.data.urls.content`; string, optional)
    - `markdown` (`spaceComposeBatch.response.201.data.urls.markdown`; string, optional)
    - `json` (`spaceComposeBatch.response.201.data.urls.json`; string, optional)
  - `composeTemplate` (`spaceComposeBatch.response.201.data.composeTemplate`; string, optional)
  - `templateHash` (`spaceComposeBatch.response.201.data.templateHash`; string, optional)
  - `composedAt` (`spaceComposeBatch.response.201.data.composedAt`; string, optional)

### 400

The reference is not a compose template (`capability_mismatch`).

### 404

Unknown template.

### 413

The rendered documents exceed the per-call output limit (`output_too_large`) — split the batch.

### 422

At least one item fails the template schema (`invalid_data`, with `errors[]` carrying `index`), two items share a file name (`duplicate_item_names`), an item `name` is not a bare file name (`invalid_item_name`), or the template is incomplete or failed to compile.

### 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` (`spaceComposeBatch.response.429.code`; string, required)
  - one of `"rate_limited"`
- `message` (`spaceComposeBatch.response.429.message`; string, required)
- `retryable` (`spaceComposeBatch.response.429.retryable`; boolean, required)
  - one of `true`
- `requestId` (`spaceComposeBatch.response.429.requestId`; string, required)
- `docUrl` (`spaceComposeBatch.response.429.docUrl`; string, optional)


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