
# Contacts and forms

Every site has a small CRM. People arrive as **contacts** when they send a form, pay, or are added by hand or by a workflow. Each contact has a **stage** in the pipeline (New lead, Qualified, Call booked…), tags, a score, and an activity history.

Reading needs `contacts:read`; changing needs `contacts:write`.

## Contacts

```sh
curl "https://api.unvop.com/v1/sites/site_…/contacts?q=rivera&limit=20" \
  -H "Authorization: Bearer $UNVOP_KEY"
```

`GET /sites/{siteId}/contacts` lists contacts, most recently active first. Search name, email and company with `q`; filter by `stage` or `tag`; page with `cursor`. `GET …/contacts/{contactId}` answers one contact with their activity, form submissions and payments.

Add someone with `POST …/contacts`. The email must be new to the site:

```json title="POST /sites/{siteId}/contacts"
{
  "email": "sam@example.com",
  "name": "Sam Rivera",
  "company": "Rivera & Co",
  "stage": "lead",
  "tags": ["website"]
}
```

`PATCH …/contacts/{contactId}` changes details, stage, tags or score; a stage move is logged in their activity. `POST …/contacts/{contactId}/notes` adds a note with `{ "text": "…" }`.

## The pipeline and activity

`GET /sites/{siteId}/pipeline` answers the site's stages and its contacts (up to 1000) to place in them, ready to draw a board. `GET /sites/{siteId}/activity` is what happened across the CRM, newest first: form submissions, notes, emails, stage moves and payments.

## Forms

A form is a set of fields and settings (where notifications go, what the visitor sees after sending). Show it on a page with a form block that names its `key`.

- `GET /sites/{siteId}/forms` lists forms with their submission counts.
- `POST …/forms` adds one with `name`, `fields` and `settings`; `PUT …/forms/{formId}` replaces them. A form's key stays the same.
- `DELETE …/forms/{formId}` deletes a form and its submissions.

Forms are content, so changing them needs `content:write`.

## Submissions

`GET /sites/{siteId}/submissions` lists sent forms, newest first. Filter by form with `formId` and page with `cursor`. `DELETE …/submissions/{submissionId}` deletes one; the contact it created stays.

To act on a submission as it arrives, don't poll: make a [workflow](https://developers.unvop.com/guides/workflows.md) with the `trigger.form` trigger. It runs for every submission, with the form, the submission and the contact.

## Payments

`GET /sites/{siteId}/payments` lists payments and subscriptions taken through Stripe on the site, newest first (up to 500). Amounts are in minor units, so `49900` in `nzd` is NZ$499.00. It needs `payments:read`.
