# Components

> A site’s own section types made from a prompt, and React components on agency plans, with their versions, reviews and approvals. 9 endpoints in the Unvop API.

A site’s own section types made from a prompt, and React components on agency plans, with their versions, reviews and approvals.

## List section types and React components

`GET /v1/sites/{siteId}/components`

Scope: `content:read`.

The site’s own kinds of section. Add one to a page with a block of its `type` (x-<key> or r-<key>) and props in the shape of its fields.

### Path parameters

- `siteId` (string, required): The site’s id.

### Query parameters

- `kind` (string): One of `section`, `react`.

### Response 200

- `items` (array of objects, required)
  - `id` (string, required)
  - `kind` (string, required): One of `section`, `react`.
  - `key` (string, required)
  - `type` (string, required): The block type to use in page content: x-<key> for a section type, r-<key> for a React component.
  - `name` (string, required)
  - `description` (string, required, nullable)
  - `liveVersion` (integer, required, nullable)
- `cursor` (string, nullable): Pass as ?cursor= to get the next page. Null when there are no more.
- `total` (integer): How many there are in all, when the list knows.

### Errors

- `401`: No key, or the key isn’t valid.
- `403`: The key lacks the scope (insufficient_scope) or the role this needs, or the site’s plan lacks the feature (feature_not_in_plan).
- `404`: Not found, or not reachable with this key.
- `422`: The body is invalid; details say which values.
- `429`: Too many requests; wait for RateLimit-Reset seconds.

### Example

```sh
curl https://api.unvop.com/v1/sites/site_123/components \
  -H "Authorization: Bearer $UNVOP_KEY"
```

## Create a section type by hand

`POST /v1/sites/{siteId}/components`

Scope: `design:write`, as a site owner or admin.

A section type from its parts: `fields`, a `template` in the template language (layout elements plus <text field>, <multiline field>, <rich field>, <image field>, <link field>, <each field> and <if field>; no static text, scripts, styles or event attributes) and `css`, scoped and filtered. Refused with the problems listed when anything is unsafe.

### Path parameters

- `siteId` (string, required): The site’s id.

### Request body (JSON)

- `name` (string, required): (up to 60 characters)
- `description` (string): (up to 300 characters)
- `fields` (array of objects, required)
  - `name` (string, required)
  - `label` (string, required)
  - `type` (string, required)
  - `fields` (array)
- `template` (string, required)
- `css` (string)
- `sample` (object)

### Response 201

- `component` (object, required)
  - `id` (string, required)
  - `kind` (string, required): One of `section`, `react`.
  - `key` (string, required)
  - `type` (string, required): The block type to use in page content: x-<key> for a section type, r-<key> for a React component.
  - `name` (string, required)
  - `description` (string, required, nullable)
  - `liveVersion` (integer, required, nullable)
  - `draft` (any, required): The working copy: section {fields, template, css, sample}; React {source, fields, sample, interactive, origins}.
  - `usedOn` (array of objects, required)
    - `id` (string, required)
    - `title` (string, required)
    - `slug` (string, required)
  - `versions` (array of objects, required)
    - `version` (integer, required)
    - `status` (string, required): One of `pending`, `approved`, `rejected`.
    - `prompt` (string, required, nullable)
    - `review` (any, required, nullable): React: the static findings and the AI review.
    - `approvedBy` (string, required, nullable)
    - `approvedAt` (string, required, nullable)
    - `createdAt` (string, required)
- `warnings` (array of strings)

### Errors

- `401`: No key, or the key isn’t valid.
- `403`: The key lacks the scope (insufficient_scope) or the role this needs, or the site’s plan lacks the feature (feature_not_in_plan).
- `404`: Not found, or not reachable with this key.
- `422`: The body is invalid; details say which values.
- `429`: Too many requests; wait for RateLimit-Reset seconds.

### Example

```sh
curl https://api.unvop.com/v1/sites/site_123/components \
  -H "Authorization: Bearer $UNVOP_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Ana",
    "fields": [
      {
        "name": "Ana",
        "label": "Role",
        "type": "richText",
        "fields": [
          {}
        ]
      }
    ],
    "template": "…"
  }'
```

## Create a section type from a prompt

`POST /v1/sites/{siteId}/components/generate`

Scope: `design:write`, as a site owner or admin.

Describe a section ("a timeline of our history with a photo per year") and get a new section type for this site: fields, a safe template and scoped CSS in the site’s style, live at once. With kind "react" (agency plans) the agent writes a React component draft instead, which must be submitted and approved before it goes live. Takes about half a minute.

### Path parameters

- `siteId` (string, required): The site’s id.

### Request body (JSON)

- `prompt` (string, required): (at least 3 characters; up to 2,000 characters)
- `kind` (string): One of `section`, `react`.

### Response 201

- `component` (object, required)
  - `id` (string, required)
  - `kind` (string, required): One of `section`, `react`.
  - `key` (string, required)
  - `type` (string, required): The block type to use in page content: x-<key> for a section type, r-<key> for a React component.
  - `name` (string, required)
  - `description` (string, required, nullable)
  - `liveVersion` (integer, required, nullable)
  - `draft` (any, required): The working copy: section {fields, template, css, sample}; React {source, fields, sample, interactive, origins}.
  - `usedOn` (array of objects, required)
    - `id` (string, required)
    - `title` (string, required)
    - `slug` (string, required)
  - `versions` (array of objects, required)
    - `version` (integer, required)
    - `status` (string, required): One of `pending`, `approved`, `rejected`.
    - `prompt` (string, required, nullable)
    - `review` (any, required, nullable): React: the static findings and the AI review.
    - `approvedBy` (string, required, nullable)
    - `approvedAt` (string, required, nullable)
    - `createdAt` (string, required)
- `warnings` (array of strings)

### Errors

- `401`: No key, or the key isn’t valid.
- `403`: The key lacks the scope (insufficient_scope) or the role this needs, or the site’s plan lacks the feature (feature_not_in_plan).
- `404`: Not found, or not reachable with this key.
- `422`: The body is invalid; details say which values.
- `429`: Too many requests; wait for RateLimit-Reset seconds.

### Example

```sh
curl https://api.unvop.com/v1/sites/site_123/components/generate \
  -H "Authorization: Bearer $UNVOP_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "Harbour Bakery is a family bakery in Falmouth. Sourdough, pastries and celebration cakes."
  }'
```

## Get a component

`GET /v1/sites/{siteId}/components/{component}`

Scope: `content:read`.

A section type or React component by id or key, with its working copy, versions (and reviews) and the pages that use it.

### Path parameters

- `siteId` (string, required): The site’s id.
- `component` (string, required): The component id or key.

### Response 200

- `id` (string, required)
- `kind` (string, required): One of `section`, `react`.
- `key` (string, required)
- `type` (string, required): The block type to use in page content: x-<key> for a section type, r-<key> for a React component.
- `name` (string, required)
- `description` (string, required, nullable)
- `liveVersion` (integer, required, nullable)
- `draft` (any, required): The working copy: section {fields, template, css, sample}; React {source, fields, sample, interactive, origins}.
- `usedOn` (array of objects, required)
  - `id` (string, required)
  - `title` (string, required)
  - `slug` (string, required)
- `versions` (array of objects, required)
  - `version` (integer, required)
  - `status` (string, required): One of `pending`, `approved`, `rejected`.
  - `prompt` (string, required, nullable)
  - `review` (any, required, nullable): React: the static findings and the AI review.
  - `approvedBy` (string, required, nullable)
  - `approvedAt` (string, required, nullable)
  - `createdAt` (string, required)

### Errors

- `401`: No key, or the key isn’t valid.
- `403`: The key lacks the scope (insufficient_scope) or the role this needs, or the site’s plan lacks the feature (feature_not_in_plan).
- `404`: Not found, or not reachable with this key.
- `429`: Too many requests; wait for RateLimit-Reset seconds.

### Example

```sh
curl https://api.unvop.com/v1/sites/site_123/components/component_123 \
  -H "Authorization: Bearer $UNVOP_KEY"
```

## Change a component

`PATCH /v1/sites/{siteId}/components/{component}`

Scope: `design:write`, as a site owner or admin.

Section types: send `instruction` for a change in plain words (the agent makes it), or the full `fields`, `template`, `css` and `sample` to save by hand; either way a new version goes live. React components: send the draft (`source`, `fields`, `sample`, `interactive`, `origins`, `name`) or an `instruction`; the draft is saved, and nothing goes live until it is submitted and approved.

### Path parameters

- `siteId` (string, required): The site’s id.
- `component` (string, required): The component id or key.

### Request body (JSON)

- `instruction` (string): (up to 2,000 characters)

### Response 200

- `component` (object, required)
  - `id` (string, required)
  - `kind` (string, required): One of `section`, `react`.
  - `key` (string, required)
  - `type` (string, required): The block type to use in page content: x-<key> for a section type, r-<key> for a React component.
  - `name` (string, required)
  - `description` (string, required, nullable)
  - `liveVersion` (integer, required, nullable)
  - `draft` (any, required): The working copy: section {fields, template, css, sample}; React {source, fields, sample, interactive, origins}.
  - `usedOn` (array of objects, required)
    - `id` (string, required)
    - `title` (string, required)
    - `slug` (string, required)
  - `versions` (array of objects, required)
    - `version` (integer, required)
    - `status` (string, required): One of `pending`, `approved`, `rejected`.
    - `prompt` (string, required, nullable)
    - `review` (any, required, nullable): React: the static findings and the AI review.
    - `approvedBy` (string, required, nullable)
    - `approvedAt` (string, required, nullable)
    - `createdAt` (string, required)
- `warnings` (array of strings)

### Errors

- `401`: No key, or the key isn’t valid.
- `403`: The key lacks the scope (insufficient_scope) or the role this needs, or the site’s plan lacks the feature (feature_not_in_plan).
- `404`: Not found, or not reachable with this key.
- `422`: The body is invalid; details say which values.
- `429`: Too many requests; wait for RateLimit-Reset seconds.

### Example

```sh
curl -X PATCH https://api.unvop.com/v1/sites/site_123/components/component_123 \
  -H "Authorization: Bearer $UNVOP_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "instruction": "…"
  }'
```

## Delete a component

`DELETE /v1/sites/{siteId}/components/{component}`

Scope: `design:write`, as a site owner or admin.

Deletes the component and its versions. Sections of this type disappear from the pages that use them.

### Path parameters

- `siteId` (string, required): The site’s id.
- `component` (string, required): The component id or key.

### Response 200

- `ok` (true, required)

### Errors

- `401`: No key, or the key isn’t valid.
- `403`: The key lacks the scope (insufficient_scope) or the role this needs, or the site’s plan lacks the feature (feature_not_in_plan).
- `404`: Not found, or not reachable with this key.
- `429`: Too many requests; wait for RateLimit-Reset seconds.

### Example

```sh
curl -X DELETE https://api.unvop.com/v1/sites/site_123/components/component_123 \
  -H "Authorization: Bearer $UNVOP_KEY"
```

## List a component’s versions

`GET /v1/sites/{siteId}/components/{component}/versions`

Scope: `content:read`.

Every version, newest first: who made and approved it, its review, and which one is live. Versions never change; publishing an older one is a rollback.

### Path parameters

- `siteId` (string, required): The site’s id.
- `component` (string, required): The component id or key.

### Response 200

- `items` (array of objects, required)
  - `version` (integer, required)
  - `status` (string, required): One of `pending`, `approved`, `rejected`.
  - `prompt` (string, required, nullable)
  - `review` (any, required, nullable): React: the static findings and the AI review.
  - `approvedBy` (string, required, nullable)
  - `approvedAt` (string, required, nullable)
  - `createdAt` (string, required)
- `cursor` (string, nullable): Pass as ?cursor= to get the next page. Null when there are no more.
- `total` (integer): How many there are in all, when the list knows.

### Errors

- `401`: No key, or the key isn’t valid.
- `403`: The key lacks the scope (insufficient_scope) or the role this needs, or the site’s plan lacks the feature (feature_not_in_plan).
- `404`: Not found, or not reachable with this key.
- `429`: Too many requests; wait for RateLimit-Reset seconds.

### Example

```sh
curl https://api.unvop.com/v1/sites/site_123/components/component_123/versions \
  -H "Authorization: Bearer $UNVOP_KEY"
```

## Send a React component for review

`POST /v1/sites/{siteId}/components/{component}/submit`

Scope: `design:write`, as a site owner or admin.

Compiles the draft, runs the static checks, renders it once in the sandbox and runs the AI review. The result is a pending version that an owner or admin approves with publishComponent.

### Path parameters

- `siteId` (string, required): The site’s id.
- `component` (string, required): The component id or key.

### Response 201

- `id` (string, required)
- `kind` (string, required): One of `section`, `react`.
- `key` (string, required)
- `type` (string, required): The block type to use in page content: x-<key> for a section type, r-<key> for a React component.
- `name` (string, required)
- `description` (string, required, nullable)
- `liveVersion` (integer, required, nullable)
- `draft` (any, required): The working copy: section {fields, template, css, sample}; React {source, fields, sample, interactive, origins}.
- `usedOn` (array of objects, required)
  - `id` (string, required)
  - `title` (string, required)
  - `slug` (string, required)
- `versions` (array of objects, required)
  - `version` (integer, required)
  - `status` (string, required): One of `pending`, `approved`, `rejected`.
  - `prompt` (string, required, nullable)
  - `review` (any, required, nullable): React: the static findings and the AI review.
  - `approvedBy` (string, required, nullable)
  - `approvedAt` (string, required, nullable)
  - `createdAt` (string, required)

### Errors

- `401`: No key, or the key isn’t valid.
- `403`: The key lacks the scope (insufficient_scope) or the role this needs, or the site’s plan lacks the feature (feature_not_in_plan).
- `404`: Not found, or not reachable with this key.
- `429`: Too many requests; wait for RateLimit-Reset seconds.

### Example

```sh
curl -X POST https://api.unvop.com/v1/sites/site_123/components/component_123/submit \
  -H "Authorization: Bearer $UNVOP_KEY"
```

## Publish a version

`POST /v1/sites/{siteId}/components/{component}/publish`

Scope: `design:write`, as a site owner or admin.

Makes `version` live. For a React component a pending version is approved first, recorded against the caller; an approved one is simply made live again (rollback). For a section type any version can be made live.

### Path parameters

- `siteId` (string, required): The site’s id.
- `component` (string, required): The component id or key.

### Request body (JSON)

- `version` (integer, required): (min 1)

### Response 200

- `id` (string, required)
- `kind` (string, required): One of `section`, `react`.
- `key` (string, required)
- `type` (string, required): The block type to use in page content: x-<key> for a section type, r-<key> for a React component.
- `name` (string, required)
- `description` (string, required, nullable)
- `liveVersion` (integer, required, nullable)
- `draft` (any, required): The working copy: section {fields, template, css, sample}; React {source, fields, sample, interactive, origins}.
- `usedOn` (array of objects, required)
  - `id` (string, required)
  - `title` (string, required)
  - `slug` (string, required)
- `versions` (array of objects, required)
  - `version` (integer, required)
  - `status` (string, required): One of `pending`, `approved`, `rejected`.
  - `prompt` (string, required, nullable)
  - `review` (any, required, nullable): React: the static findings and the AI review.
  - `approvedBy` (string, required, nullable)
  - `approvedAt` (string, required, nullable)
  - `createdAt` (string, required)

### Errors

- `401`: No key, or the key isn’t valid.
- `403`: The key lacks the scope (insufficient_scope) or the role this needs, or the site’s plan lacks the feature (feature_not_in_plan).
- `404`: Not found, or not reachable with this key.
- `422`: The body is invalid; details say which values.
- `429`: Too many requests; wait for RateLimit-Reset seconds.

### Example

```sh
curl https://api.unvop.com/v1/sites/site_123/components/component_123/publish \
  -H "Authorization: Bearer $UNVOP_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "version": 1
  }'
```
