# REST API

The API lets your own systems read forms and submissions, delete submissions, and subscribe to new ones. It is the same data your team sees in the panel, returned as JSON.

An API key can read every submission in the workspace, and submissions are usually protected health information. Only give a key to systems covered by your HIPAA policies and, where required, a Business Associate Agreement.

## Authentication

An account owner creates keys under **Workspace → API keys**, after confirming responsibility for where the data goes. A key is shown once; store it in a secret manager. Revoking a key takes effect immediately and removes its subscriptions.

Send the key as a bearer token on every request:

```bash
curl https://app.hipaaform.ai/api/v1/forms \
  -H "Authorization: Bearer hf_live_your_key"
```

- Base URL: `https://app.hipaaform.ai/api/v1`
- All requests must use `https`. All responses are JSON and are never cached.
- Each key may make 120 requests per minute. Beyond that the API answers `429` with a `Retry-After` header.
- Every read, download and deletion made with a key is recorded in the workspace audit log under the key's name.

## Errors

Errors use the HTTP status and a JSON body:

```json
{ "error": { "code": "not_found", "message": "No form with that id." } }
```

| Status | `code` | Meaning |
|---|---|---|
| 400 | `bad_request` | A parameter is missing or malformed. |
| 401 | `unauthorized` | The key is missing, wrong or revoked. |
| 403 | `plan`, `workspace_inactive` | API access is not included in the plan, or the workspace is suspended. |
| 404 | `not_found` | No such object in this workspace. |
| 429 | — | Too many requests. |

## Forms

### `GET /forms`

Lists the workspace's forms (not those in the trash).

```json
{
  "data": [
    { "id": "k6mswsvebqry", "name": "New patient intake", "status": "published",
      "created_at": "2026-11-02T15:04:11.482Z", "updated_at": "2026-11-20T09:12:40.118Z", "submission_count": 214 }
  ]
}
```

### `GET /forms/{form_id}`

One form, with its fields: `id`, `type`, `label`, `required`, and `options` or `rows` where the field has them. Field ids are stable, so use them — not labels — to map answers.

## Submissions

### `GET /forms/{form_id}/submissions`

Newest first.

| Parameter | Meaning |
|---|---|
| `limit` | 1–100, default 25. |
| `before` | Return submissions older than this time. Pass the previous response's `next_cursor` to page backwards. |
| `since` | Return submissions newer than this ISO 8601 time. Use it to poll for new ones. |

```json
{
  "data": [
    {
      "id": "sub_w9puhp9hpwy6uyvxco",
      "form_id": "k6mswsvebqry",
      "created_at": "2026-11-22T06:18:56.337Z",
      "read": false,
      "answers": [
        { "id": "f_a1b2c3d4", "label": "Full name", "type": "text", "value": "Ada Lovelace" },
        { "id": "f_e5f6g7h8", "label": "Home address", "type": "address",
          "value": { "street": "12 Analytical Way", "line2": "", "city": "Reno", "state": "NV", "zip": "89501" } },
        { "id": "f_j9k1m2n3", "label": "Insurance card", "type": "file",
          "value": [ { "id": "file_Zk3…", "name": "card.png", "size": 48211, "type": "image/png" } ] }
      ],
      "signed": true,
      "attribution": { "tracking": { "utm_source": "google" }, "pageUrl": "https://example.com/new-patients" }
    }
  ],
  "next_cursor": "2026-11-22T06:18:56.337Z"
}
```

`next_cursor` is `null` on the last page. Signature images are not included; `signed` says whether the form was signed. Answer values by type:

| Type | Value |
|---|---|
| text, long text, email, phone, date, date of birth, dropdown, single choice | string |
| number, rating scale, calculated score | number |
| multiple choice | array of strings |
| consent | boolean |
| address | object: `street`, `line2`, `city`, `state`, `zip` |
| insurance | object: `provider`, `memberId`, `groupNumber`, `holderName`, `relationship` |
| question grid | array of `{ "row", "value" }` |
| file upload | array of `{ "id", "name", "size", "type" }` |

### `GET /submissions/{submission_id}`

One submission, in the same shape.

### `GET /submissions/{submission_id}/files/{file_id}`

Downloads an attached file as `application/octet-stream`.

### `DELETE /submissions/{submission_id}`

Permanently deletes a submission and its files. Answers `204`.

## Subscriptions

A subscription has hipaaform.ai `POST` every new submission to a URL of yours as soon as it arrives. This is how Zapier, Make and n8n receive submissions instantly. The request, payload and signature are identical to a [webhook](https://app.hipaaform.ai/docs/webhooks), deliveries are retried the same way, and they appear in each form's delivery log.

### `POST /hooks`

```bash
curl -X POST https://app.hipaaform.ai/api/v1/hooks \
  -H "Authorization: Bearer hf_live_your_key" -H "Content-Type: application/json" \
  -d '{ "url": "https://example.com/hooks/hipaaform", "form_id": "k6mswsvebqry" }'
```

Omit `form_id` to subscribe to every form. The response (`201`) includes the subscription `id` and its signing `secret`, which is returned only this once.

### `POST /hooks/{hook_id}/test`

Sends one signed sample event to the subscription's URL straight away, so you can build and check a receiver before any real submission exists. The payload has the same shape as a real one, with made-up answers, `"test": true` at the top level and the submission id `test_submission`. Answers `200` with `{ "delivered": true }`, or `502` with the reason when your endpoint did not accept it. A test is sent once and is not retried.

### `GET /hooks`

Lists subscriptions.

### `DELETE /hooks/{hook_id}`

Removes one. Answers `204`.
