# Code, template and form management

Use a [personal API key or OAuth](https://cli.im/open-api/en/openapi/v2/auth.md). Send JSON directly in the body of a POST to `https://open.cli.im/api/v2/rpc/` plus the path below. The [openapi.json spec](https://cli.im/open-api/en/openapi/v2/overview.md#openapi-json) lists request schemas and operation IDs. These endpoints do not accept [legacy organization keys](https://cli.im/open-api/en/openapi/v2/auth.md#org-key).

For code creation, choose Read/write when you [create your key](https://cli.im/open-api/en/openapi/v2/auth.md#create-key). To edit supported manually created content or delete, check both the [organization ceiling](https://cli.im/open-api/en/openapi/v2/auth.md#org-policy) and the credential level.

## Create one code from an official template

Call `gallery/get` with the template ID and check `data.template.compatibility.can_create_single`. Then send the following body to `gallery/create-qrcode`. Choose one idempotency key per intended creation and keep it if the outcome is unclear. Read `data.status`, `data.qrcode_id` and `data.web_url` before deciding what to do next.

```json
{"gallery_template_id":"57751068","name":"Boiler 01","idempotency_key":"boiler-01-install-001"}
```

## Step-by-step flows

Multi-step flows have their own scenario pages with the full call sequence and request examples:

- [Create codes in bulk from a template](https://cli.im/open-api/en/openapi/v2/scenarios/batch-create-qrcodes.md), including [uploading images and attachments](https://cli.im/open-api/en/openapi/v2/scenarios/batch-create-qrcodes.md#upload)
- [Edit and delete codes and forms](https://cli.im/open-api/en/openapi/v2/scenarios/edit-and-delete.md)
- [Export printable labels](https://cli.im/open-api/en/openapi/v2/scenarios/export-labels.md)

## Endpoints by task

See the [API list](https://cli.im/open-api/en/openapi/v2/api-index.md) for the minimum permission each endpoint needs.

| Task | Paths under `/api/v2/rpc/` |
|---|---|
| Find an official template and create codes in bulk | `gallery/categories`, `gallery/list`, `gallery/get`, `gallery/prepare-creation`, `gallery/create-from-plan` |
| Create or edit a template | `templates/listEditable`, `templates/getSchema`, `templates/create`, `templates/previewEdit`, `templates/edit` |
| Create codes and check batch results | `qrcodes/listCreateTargets`, `qrcodes/create`, `qrcodes/createUrlJump`, `qrcodes/createMultiUrl`, `staticQrcodes/create`, `qrcodes/prevalidate`, `qrcodes/createBatch`, `qrcodeTasks/get`, `qrcodeTasks/getResults` |
| Edit a code or form | `qrcodes/getEditState`, `qrcodes/edit`, `qrcodes/editUrlJump`, `qrcodes/editMultiUrl`, `qrcodeChildren/edit`, `forms/create`, `forms/getEditState`, `forms/edit` |
| Preview and delete | `qrcodes/previewDelete`, `qrcodes/delete`, `forms/previewDelete`, `forms/delete` |
| Upload media, preview or export labels | `assets/requestUpload`, `assets/getUpload`, `labels/getConfig`, `labels/preview`, `labelExports/create`, `labelExports/get` |
| Read recurring plans and completion | `cyclePlans/list`, `cyclePlans/get`, `cycleTasks/listQrcodes`, `cycleTasks/getCompletion` |
| Read follow-up activity on a record | `record/getActivities` |
| Inspect permissions and quota | `auth/getContext`, `usage/get` |

For bulk creation, add `extra_fields` only when the template reports `can_add_fields`. When editing template body components, preview the complete component list first. Omitting an existing component removes it. To delete, preview the IDs, confirm the returned items, then submit the same IDs, `confirm_token` and an idempotency key. Deletion requires Full access. Forms must be unlinked before deletion.

See [shared limits and retry behavior](https://cli.im/open-api/en/openapi/v2/error-codes.md#rate-limit).
