# Forms

> Forms and what people sent through them. 7 endpoints in the Unvop API.

Forms and what people sent through them.

## List forms

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

Scope: `content:read`.

The site’s forms with their fields, settings and submission counts.

### Path parameters

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

### Response 200

- `items` (array of objects, required)
  - `id` (string, required)
  - `key` (string, required)
  - `name` (string, required)
  - `fields` (array, required)
  - `settings` (object, required)
  - `submissionCount` (number)
- `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/forms \
  -H "Authorization: Bearer $UNVOP_KEY"
```

## Create a form

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

Scope: `content:write`.

Add a form. Show it on a page with a form block that names its key.

### Path parameters

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

### Headers

- `Idempotency-Key` (string): Send the same key to repeat this request safely; the first answer is replayed for 24 hours. (up to 200 characters)

### Request body (JSON)

- `key` (string): The handle blocks use to show the form. Made from the name when left out. (up to 60 characters)
- `name` (string, required): (at least 1 characters; up to 120 characters)
- `fields` (array of objects, required): (up to 40 items)
  - `name` (string, required): Letters, numbers, - and _.
  - `label` (string, required)
  - `type` (string, required): One of `text`, `email`, `tel`, `url`, `textarea`, `select`, `radio`, `checkbox`, `checkboxes`, `hidden`.
  - `required` (boolean)
  - `placeholder` (string)
  - `help` (string)
  - `options` (array of strings)
  - `mapsTo` (string): Which contact detail the answer fills in. One of `email`, `name`, `company`, `phone`.
  - `width` (string): One of `full`, `half`.
- `settings` (object, required): What happens after someone sends it.
  - `submitLabel` (string)
  - `successTitle` (string)
  - `successMessage` (string)
  - `redirect` (string)
  - `notify` (array of strings): Email addresses told about each submission.
  - `autoresponder` (object)
    - `enabled` (boolean, required)
    - `subject` (string, required)
    - `body` (string, required)

### Response 201

- `id` (string, required)
- `key` (string, required)
- `name` (string, required)
- `fields` (array, required)
- `settings` (object, required)
- `submissionCount` (number)

### 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/forms \
  -H "Authorization: Bearer $UNVOP_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" \
  -d '{
    "name": "Ana",
    "fields": [
      {
        "name": "Ana",
        "label": "Role",
        "type": "text",
        "required": true,
        "options": [],
        "mapsTo": "email",
        "width": "full"
      }
    ],
    "settings": {
      "notify": [],
      "autoresponder": {
        "enabled": true,
        "subject": "…",
        "body": "…"
      }
    }
  }'
```

## Get a form

`GET /v1/sites/{siteId}/forms/{formId}`

Scope: `content:read`.

One form.

### Path parameters

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

### Response 200

- `id` (string, required)
- `key` (string, required)
- `name` (string, required)
- `fields` (array, required)
- `settings` (object, required)
- `submissionCount` (number)

### 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/forms/frm_123 \
  -H "Authorization: Bearer $UNVOP_KEY"
```

## Replace a form

`PUT /v1/sites/{siteId}/forms/{formId}`

Scope: `content:write`.

Replace a form’s name, fields and settings. Its key stays the same.

### Path parameters

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

### Request body (JSON)

- `key` (string): The handle blocks use to show the form. Made from the name when left out. (up to 60 characters)
- `name` (string, required): (at least 1 characters; up to 120 characters)
- `fields` (array of objects, required): (up to 40 items)
  - `name` (string, required): Letters, numbers, - and _.
  - `label` (string, required)
  - `type` (string, required): One of `text`, `email`, `tel`, `url`, `textarea`, `select`, `radio`, `checkbox`, `checkboxes`, `hidden`.
  - `required` (boolean)
  - `placeholder` (string)
  - `help` (string)
  - `options` (array of strings)
  - `mapsTo` (string): Which contact detail the answer fills in. One of `email`, `name`, `company`, `phone`.
  - `width` (string): One of `full`, `half`.
- `settings` (object, required): What happens after someone sends it.
  - `submitLabel` (string)
  - `successTitle` (string)
  - `successMessage` (string)
  - `redirect` (string)
  - `notify` (array of strings): Email addresses told about each submission.
  - `autoresponder` (object)
    - `enabled` (boolean, required)
    - `subject` (string, required)
    - `body` (string, required)

### Response 200

- `id` (string, required)
- `key` (string, required)
- `name` (string, required)
- `fields` (array, required)
- `settings` (object, required)
- `submissionCount` (number)

### 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 PUT https://api.unvop.com/v1/sites/site_123/forms/frm_123 \
  -H "Authorization: Bearer $UNVOP_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Ana",
    "fields": [
      {
        "name": "Ana",
        "label": "Role",
        "type": "text",
        "required": true,
        "options": [],
        "mapsTo": "email",
        "width": "full"
      }
    ],
    "settings": {
      "notify": [],
      "autoresponder": {
        "enabled": true,
        "subject": "…",
        "body": "…"
      }
    }
  }'
```

## Delete a form

`DELETE /v1/sites/{siteId}/forms/{formId}`

Scope: `content:write`.

Delete a form and its submissions.

### Path parameters

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

### 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/forms/frm_123 \
  -H "Authorization: Bearer $UNVOP_KEY"
```

## List submissions

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

Scope: `contacts:read`.

Sent forms, newest first. Filter by form with formId.

### Path parameters

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

### Query parameters

- `limit` (integer): How many to return (default 50). (min 1; max 200)
- `cursor` (string): The cursor from the previous page.
- `formId` (string)

### Response 200

- `items` (array of objects, required)
  - `id` (string, required)
  - `formId` (string, required)
  - `formName` (string)
  - `contactId` (string, nullable)
  - `data` (object, required)
  - `createdAt` (string, required): An ISO 8601 timestamp.
- `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/submissions \
  -H "Authorization: Bearer $UNVOP_KEY"
```

## Delete a submission

`DELETE /v1/sites/{siteId}/submissions/{submissionId}`

Scope: `contacts:write`.

Delete one sent form. The contact it created stays.

### Path parameters

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

### 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/submissions/sub_123 \
  -H "Authorization: Bearer $UNVOP_KEY"
```
