# Contacts

> The CRM: contacts, the pipeline and activity. 8 endpoints in the Unvop API.

The CRM: contacts, the pipeline and activity.

## List contacts

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

Scope: `contacts:read`.

Contacts, most recently active first. Search name, email and company with q; filter by stage or tag.

### 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.
- `q` (string)
- `stage` (string)
- `tag` (string)

### Response 200

- `items` (array of objects, required)
  - `id` (string, required)
  - `email` (string, required)
  - `name` (string)
  - `company` (string)
  - `phone` (string)
  - `stage` (string, required)
  - `tags` (array of strings, required)
  - `score` (number, required)
  - `source` (string)
  - `data` (object, required)
  - `createdAt` (string, required): An ISO 8601 timestamp.
  - `updatedAt` (string, required): An ISO 8601 timestamp.
  - `lastActivityAt` (string): 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/contacts \
  -H "Authorization: Bearer $UNVOP_KEY"
```

## Add a contact

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

Scope: `contacts:write`.

Add a person to the CRM. The email must be new to this site.

### 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)

- `email` (string, required): (email)
- `name` (string): (up to 200 characters)
- `company` (string): (up to 200 characters)
- `phone` (string): (up to 60 characters)
- `stage` (string): A pipeline stage id from GET /sites/{siteId}/pipeline. (up to 40 characters)
- `tags` (array of strings): (up to 30 items)
- `score` (integer)
- `source` (string): (up to 100 characters)
- `data` (object): Extra details. Merged into what is stored.

### Response 201

- `id` (string, required)
- `email` (string, required)
- `name` (string)
- `company` (string)
- `phone` (string)
- `stage` (string, required)
- `tags` (array of strings, required)
- `score` (number, required)
- `source` (string)
- `data` (object, required)
- `createdAt` (string, required): An ISO 8601 timestamp.
- `updatedAt` (string, required): An ISO 8601 timestamp.
- `lastActivityAt` (string): An ISO 8601 timestamp.

### 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/contacts \
  -H "Authorization: Bearer $UNVOP_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" \
  -d '{
    "email": "sam@example.com"
  }'
```

## Get a contact

`GET /v1/sites/{siteId}/contacts/{contactId}`

Scope: `contacts:read`.

A contact with their activity, form submissions and payments.

### Path parameters

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

### Response 200

- `contact` (object, required): A person in the CRM.
  - `id` (string, required)
  - `email` (string, required)
  - `name` (string)
  - `company` (string)
  - `phone` (string)
  - `stage` (string, required)
  - `tags` (array of strings, required)
  - `score` (number, required)
  - `source` (string)
  - `data` (object, required)
  - `createdAt` (string, required): An ISO 8601 timestamp.
  - `updatedAt` (string, required): An ISO 8601 timestamp.
  - `lastActivityAt` (string): An ISO 8601 timestamp.
- `activities` (array of objects, required)
  - `id` (string, required)
  - `contactId` (string, required)
  - `type` (string, required)
  - `summary` (string, required)
  - `createdAt` (string, required): An ISO 8601 timestamp.
- `submissions` (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.
- `payments` (array of objects, required)
  - `id` (string, required)
  - `amount` (number, required): In minor units (cents).
  - `currency` (string, required)
  - `status` (string, required)
  - `mode` (string, required): One of `payment`, `subscription`.
  - `contactEmail` (string)
  - `createdAt` (string, required): An ISO 8601 timestamp.

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

## Change a contact

`PATCH /v1/sites/{siteId}/contacts/{contactId}`

Scope: `contacts:write`.

Change a contact’s details, stage, tags or score. Moving stage is logged in their activity.

### Path parameters

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

### Request body (JSON)

- `email` (string): (email)
- `name` (string): (up to 200 characters)
- `company` (string): (up to 200 characters)
- `phone` (string): (up to 60 characters)
- `stage` (string): A pipeline stage id from GET /sites/{siteId}/pipeline. (up to 40 characters)
- `tags` (array of strings): (up to 30 items)
- `score` (integer)
- `source` (string): (up to 100 characters)
- `data` (object): Extra details. Merged into what is stored.

### Response 200

- `id` (string, required)
- `email` (string, required)
- `name` (string)
- `company` (string)
- `phone` (string)
- `stage` (string, required)
- `tags` (array of strings, required)
- `score` (number, required)
- `source` (string)
- `data` (object, required)
- `createdAt` (string, required): An ISO 8601 timestamp.
- `updatedAt` (string, required): An ISO 8601 timestamp.
- `lastActivityAt` (string): An ISO 8601 timestamp.

### 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/contacts/con_123 \
  -H "Authorization: Bearer $UNVOP_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "email": "sam@example.com",
    "name": "Ana"
  }'
```

## Delete a contact

`DELETE /v1/sites/{siteId}/contacts/{contactId}`

Scope: `contacts:write`.

Delete a contact and their activity.

### Path parameters

- `siteId` (string, required): The site’s id.
- `contactId` (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/contacts/con_123 \
  -H "Authorization: Bearer $UNVOP_KEY"
```

## Add a note

`POST /v1/sites/{siteId}/contacts/{contactId}/notes`

Scope: `contacts:write`.

Add a note to a contact’s activity.

### Path parameters

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

### Request body (JSON)

- `text` (string, required): (at least 1 characters; up to 5,000 characters)

### Response 201

- `id` (string, required)
- `contactId` (string, required)
- `type` (string, required)
- `summary` (string, required)
- `createdAt` (string, required): An ISO 8601 timestamp.

### 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/contacts/con_123/notes \
  -H "Authorization: Bearer $UNVOP_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "text": "Called back about the Open Water course."
  }'
```

## Get the pipeline

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

Scope: `contacts:read`.

The site’s pipeline stages (New lead, Qualified, Call booked…) and its contacts (up to 1000) to place in them.

### Path parameters

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

### Response 200

- `stages` (array of objects, required)
  - `id` (string, required)
  - `label` (string, required)
- `contacts` (array of objects, required)
  - `id` (string, required)
  - `email` (string, required)
  - `name` (string)
  - `company` (string)
  - `phone` (string)
  - `stage` (string, required)
  - `tags` (array of strings, required)
  - `score` (number, required)
  - `source` (string)
  - `data` (object, required)
  - `createdAt` (string, required): An ISO 8601 timestamp.
  - `updatedAt` (string, required): An ISO 8601 timestamp.
  - `lastActivityAt` (string): An ISO 8601 timestamp.

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

## Recent activity

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

Scope: `contacts:read`.

What happened across the CRM, newest first: form submissions, notes, emails, stage moves, payments.

### Path parameters

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

### Query parameters

- `limit` (integer): (min 1; max 200)

### Response 200

- `items` (array of objects, required)
  - `id` (string, required)
  - `contactId` (string, required)
  - `type` (string, required)
  - `summary` (string, required)
  - `createdAt` (string, required): An ISO 8601 timestamp.

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