
## Upload a template

`POST /v1/bizproc-templates`

Uploads a business process template from a BPT file and binds it to a document type. Fields are passed flat at the JSON root — without a `fields` wrapper.

## Request fields (body)

| Field | Type | Req. | Description |
|------|-----|:-----:|---------|
| `templateData` | array | yes | Template file as two elements — the file name and its contents in base64. Example: `["process.bpt", "eNrlWNtO41YUfe..."]` |
| `documentType` | array | yes | Document type `[module, object, type]`. Values:<br>`["crm", "CCrmDocumentLead", "LEAD"]` — leads<br>`["crm", "CCrmDocumentContact", "CONTACT"]` — contacts<br>`["crm", "CCrmDocumentCompany", "COMPANY"]` — companies<br>`["crm", "CCrmDocumentDeal", "DEAL"]` — deals<br>`["crm", "Bitrix\\Crm\\Integration\\BizProc\\Document\\Quote", "QUOTE"]` — quotes<br>`["crm", "Bitrix\\Crm\\Integration\\BizProc\\Document\\SmartInvoice", "SMART_INVOICE"]` — invoices<br>`["crm", "Bitrix\\Crm\\Integration\\BizProc\\Document\\Dynamic", "DYNAMIC_<entityTypeId>"]` — smart processes, `<entityTypeId>` from the `entityTypeId` field in [GET /v1/smart-processes](/docs/entities/smart-processes/list)<br>`["lists", "BizprocDocument", "iblock_<id>"]` — processes in the Feed<br>`["lists", "Bitrix\\Lists\\BizprocDocumentLists", "iblock_<id>"]` — lists in workgroups<br>`["disk", "Bitrix\\Disk\\BizProcDocument", "STORAGE_<id>"]` — Drive documents |
| `name` | string | yes | Template name. Bitrix24 rejects an empty value |
| `description` | string | no | Template description |
| `autoExecute` | number | no | Autostart condition: `0` — no autostart, `1` — on document creation, `2` — on change, `3` — on creation and change. Defaults to `0` |

## Examples

Only an authorization key can upload templates — both examples send the authorization key and the `Authorization: Bearer` header. The session token is issued by OAuth authorization, is valid for 24 hours, and cannot be renewed — [Passing the key](/docs/keys-auth#passing-the-key).

### curl — authorization key

```bash
curl -X POST "https://vibecode.bitrix24.com/v1/bizproc-templates" \
  -H "X-Api-Key: YOUR_APP_KEY" \
  -H "Authorization: Bearer USER_SESSION_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "documentType": ["crm", "CCrmDocumentDeal", "DEAL"],
    "name": "Deal approval",
    "description": "Uploaded from the application",
    "autoExecute": 0,
    "templateData": ["approval.bpt", "eNrlWNtO41YUfe..."]
  }'
```

### JavaScript — authorization key

```javascript
import { readFile } from 'node:fs/promises'

const file = await readFile('approval.bpt')

const res = await fetch('https://vibecode.bitrix24.com/v1/bizproc-templates', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_APP_KEY',
    'Authorization': 'Bearer USER_SESSION_TOKEN',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    documentType: ['crm', 'CCrmDocumentDeal', 'DEAL'],
    name: 'Deal approval',
    description: 'Uploaded from the application',
    autoExecute: 0,
    templateData: ['approval.bpt', file.toString('base64')],
  }),
})

const { success, data } = await res.json()
console.log(`Template identifier: ${data.id}`)
```

## Response fields

| Field | Type | Description |
|------|-----|---------|
| `success` | boolean | Always `true` on success |
| `data.id` | number | Identifier of the created template. Used in the update and delete paths |

## Response example

```json
{
  "success": true,
  "data": {
    "id": 1215
  }
}
```

## Error response example

400 — the template file was not passed:

```json
{
  "success": false,
  "error": {
    "code": "MISSING_REQUIRED_FIELDS",
    "message": "Body field \"templateData\" is required to create bizprocTemplate."
  }
}
```

## Errors

| HTTP | Code | Description |
|------|-----|----------|
| 400 | `MISSING_REQUIRED_FIELDS` | The `templateData` field was not passed |
| 422 | `BITRIX_ERROR` | `name` was not passed — message `Empty template name!`, the `b24Code` field contains `ERROR_TEMPLATE_VALIDATION_FAILURE` |
| 422 | `BITRIX_ERROR` | `documentType` was not passed or an unknown type was given — message `Incorrect field DOCUMENT_TYPE!`, the `b24Code` field contains `ERROR_TEMPLATE_VALIDATION_FAILURE` |
| 422 | `BITRIX_ERROR` | The file contents were not recognized as a template. Bitrix24 returns the `message` text in the account language |
| 403 | `OAUTH_REQUIRED` | The request was sent with an API key. Only an authorization key can upload templates |
| 401 | `TOKEN_MISSING` | Authorization key without the `Authorization: Bearer` header |
| 401 | `WRONG_AUTH_SCHEME` | The authorization key was sent in the `Authorization: Bearer` header. The key goes in `X-Api-Key`, while `Authorization: Bearer` carries the session token |
| 401 | `INVALID_SESSION` | The session token has expired or is invalid — authorize again |
| 403 | `SCOPE_DENIED` | The key lacks the `bizproc` scope |

On a Bitrix24-side error the `error` object gains a `b24Code` field — the machine-readable reason code.

The full list of common API errors — [Errors](/docs/errors).

## Known specifics

**The `.bpt` file is prepared in Bitrix24.** Configure the process in the business process designer and export it to a file — that file is what you pass in `templateData`. The contents of a `.bpt` file cannot be assembled through the API, so preparing the file stays a manual step.

**The response does not show what was written.** Only `id` is returned, so check the applied values by reading the record through [`GET /v1/bizproc-templates`](./list.md) with a filter by `id`.

## See also

- [Template list](/docs/entities/bizproc-templates/list)
- [Template fields](/docs/entities/bizproc-templates/fields)
- [Update a template](/docs/entities/bizproc-templates/update)
- [Delete a template](/docs/entities/bizproc-templates/delete)
- [Keys and authorization](/docs/keys-auth)
