# Forms and surveys API

> Read forms and their answers, and send a form. GET /api/v1/forms, GET /api/v1/forms/{id}, GET /api/v1/forms/{id}/responses, POST /api/v1/forms/{id}/send.

4 operations. Each needs an API key with the permission shown; see [API keys and permissions](https://staffedly.com/docs/developers/api-keys).

| Operation | Permission |
| --- | --- |
| [`GET /api/v1/forms`](#get-api-v1-forms) | `forms:read` |
| [`GET /api/v1/forms/{id}`](#get-api-v1-forms-id) | `forms:read` |
| [`GET /api/v1/forms/{id}/responses`](#get-api-v1-forms-id-responses) | `forms:read` |
| [`POST /api/v1/forms/{id}/send`](#post-api-v1-forms-id-send) | `forms:write` |

## GET /api/v1/forms

Forms and surveys.

- **Permission:** `forms:read`
- **Returns:** a page of records: `{ data, hasMore, nextCursor }`, status 200

**Query parameters** (all optional)

| Name | Description |
| --- | --- |
| `status` | draft, open or closed. |
| `limit` | Rows per page, 1 to 200. Default 50. |
| `cursor` | The nextCursor value from the previous page. |

**Fields in each record:** `id`, `name`, `title`, `purpose`, `audience`, `status`, `publicLinkOn`, `responseCount`, `lastResponseAt`, `createdAt`, `updatedAt`

```bash
curl "https://app.staffedly.com/api/v1/forms?limit=50" \
  -H "Authorization: Bearer $STAFFEDLY_API_KEY"
```

## GET /api/v1/forms/{id}

One form with its questions. The rules that open an Issue stay in Staffedly.

- **Permission:** `forms:read`
- **Returns:** one record: `{ data }`, status 200

**Path**

| Name | Description |
| --- | --- |
| `id` | The record's id. |

**Fields in each record:** `id`, `name`, `title`, `purpose`, `audience`, `status`, `publicLinkOn`, `responseCount`, `lastResponseAt`, `createdAt`, `updatedAt`, `intro`, `fields`, `closesAt`

```bash
curl "https://app.staffedly.com/api/v1/forms/<id>" \
  -H "Authorization: Bearer $STAFFEDLY_API_KEY"
```

## GET /api/v1/forms/{id}/responses

The answers to one form. Answers filed on an applicant are included only for a key that also has Recruiting: read. Uploaded files are named, not served.

- **Permission:** `forms:read`
- **Returns:** a page of records: `{ data, hasMore, nextCursor }`, status 200

**Path**

| Name | Description |
| --- | --- |
| `id` | The record's id. |

**Query parameters** (all optional)

| Name | Description |
| --- | --- |
| `from` | Earliest answer time: YYYY-MM-DD or an ISO-8601 time. |
| `to` | Latest answer time (not included): YYYY-MM-DD or an ISO-8601 time. |
| `flagged` | true for answers the form's own rules marked worth a look. |
| `limit` | Rows per page, 1 to 200. Default 50. |
| `cursor` | The nextCursor value from the previous page. |

**Fields in each record:** `id`, `formId`, `source`, `providerId`, `facilityId`, `applicationId`, `assignmentId`, `respondentName`, `respondentEmail`, `flagged`, `issueId`, `answers`, `files`, `createdAt`

```bash
curl "https://app.staffedly.com/api/v1/forms/<id>/responses?limit=50" \
  -H "Authorization: Bearer $STAFFEDLY_API_KEY"
```

## POST /api/v1/forms/{id}/send

Email an open form to providers, facilities (their contacts) or applicants, each with a private link. A provider's email consent applies. Up to 200 at a time. Applicants also need Recruiting: write.

- **Permission:** `forms:write`
- **Returns:** one record: `{ data }`, status 200
- **Safe retry:** send an `Idempotency-Key` header (8 to 128 characters); the same key with the same request returns the first answer again

**Path**

| Name | Description |
| --- | --- |
| `id` | The record's id. |

**Body fields** (JSON; a field the API does not know is refused)

| Field | Description |
| --- | --- |
| `providerIds` | List of provider ids. |
| `facilityIds` | List of facility ids. |
| `applicationIds` | List of application ids. |
| `note` | Optional line added to the email. |

**Fields in each record:** `results`

```bash
curl -X POST "https://app.staffedly.com/api/v1/forms/<id>/send" \
  -H "Authorization: Bearer $STAFFEDLY_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{"providerIds":["<providerId>"],"facilityIds":"<facilityIds>"}'
```

