# Opportunities API

> Deals, their stages, contacts and amounts. Every route, its parameters and fields.

Deals, their stages, contacts and amounts. 11 routes; send a bearer token with each (see [Authentication](/api/authentication.md)).

| Route | What it does |
| --- | --- |
| `GET /v1/opportunities` | List opportunities |
| `POST /v1/opportunities` | Create a deal |
| `GET /v1/opportunities/{id}` | Get a deal |
| `PATCH /v1/opportunities/{id}` | Update a deal |
| `DELETE /v1/opportunities/{id}` | Delete a deal (soft delete) |
| `POST /v1/opportunities/{id}/restore` | Restore a deleted deal |
| `GET /v1/opportunities/{id}/contacts` | List a deal's contacts |
| `POST /v1/opportunities/{id}/contacts` | Add a deal contact |
| `PATCH /v1/opportunities/{id}/contacts/{childId}` | Update a deal contact |
| `DELETE /v1/opportunities/{id}/contacts/{childId}` | Remove a deal contact |
| `GET /v1/pipelines/{id}/board` | A pipeline's board |

## List opportunities

`GET https://staging-api.naruskacrm.com/v1/opportunities`

Declared filters only (an unknown one is refused); `q` searches the name (accent- and case-insensitive); `sort` takes a declared field, `-` for descending. Pass `next_cursor` back as `cursor`. Custom fields: `custom.<api_key>` for picklists (options by key or label, comma-separated: any of them), multi-picklists (contains any) and booleans (`false` also matches empty); `custom.<api_key>_from` / `_to` for numbers and dates. The applied custom filters come back with their labels in `custom_filters`.

### Parameters

| Parameter | In | Type | Required | Notes |
| --- | --- | --- | --- | --- |
| `limit` | query | integer |  | 1–200, default `50` |
| `cursor` | query | string |  | next_cursor of the previous page. 1–400 characters |
| `owner` | query | `me` or string (uuid) |  |  |
| `pipeline_id` | query | string (uuid) |  |  |
| `stage` | query | string |  | at most 63 characters |
| `category` | query | `open`, `won`, `lost` |  |  |
| `account_id` | query | string (uuid) |  |  |
| `contact_id` | query | string (uuid) |  |  |
| `source_campaign_id` | query | string (uuid) |  | Deals from this campaign |
| `tag` | query | string |  | at most 100 characters |
| `close_date_from` | query | string (date) |  |  |
| `close_date_to` | query | string (date) |  |  |
| `closed_from` | query | string (date) or string (date-time) |  | Won or lost on or after (the stage change into won or lost) |
| `closed_to` | query | string (date) or string (date-time) |  | Won or lost on or before |
| `created_from` | query | string (date) or string (date-time) |  |  |
| `created_to` | query | string (date) or string (date-time) |  |  |
| `q` | query | string |  | 1–200 characters |
| `sort` | query | `name`, `-name`, `account_name`, `-account_name`, `amount_base`, `-amount_base`, `expected_close_date`, `-expected_close_date`, `stage_order`, `-stage_order`, `owner_name`, `-owner_name`, `created_at`, `-created_at`, `updated_at`, `-updated_at` |  | Sort by name, account_name, amount_base, expected_close_date, stage_order, owner_name, created_at, updated_at; prefix "-" for descending. |
| `updated_since` | query | string (date-time) |  |  |
| `include_deleted` | query | `true`, `false` |  |  |

### Response 200

| Field | Type | Always present | Notes |
| --- | --- | --- | --- |
| `data` | array of [Opportunity](/api/reference/objects.md#opportunity) | yes |  |
| `next_cursor` | string or null | yes |  |
| `custom_filters` | array of [CustomFilter](/api/reference/objects.md#customfilter) |  |  |

Errors are problem details with a stable `code`: see [Errors](/errors.md).

## Create a deal

`POST https://staging-api.naruskacrm.com/v1/opportunities`

### Request body

| Field | Type | Required | Notes |
| --- | --- | --- | --- |
| `name` | string | yes | 1–200 characters |
| `account_id` | string (uuid) or null |  |  |
| `pipeline_id` | string (uuid) |  |  |
| `stage_id` | string (uuid) |  |  |
| `stage` | string |  | at most 63 characters |
| `owner_user_id` | string (uuid) or null |  |  |
| `owner_team_id` | string (uuid) or null |  |  |
| `amount` | number or null |  | 0–10000000000000000 |
| `amount_source` | `estimate`, `quote` or null |  |  |
| `currency` | string |  |  |
| `expected_close_date` | string (date) or null |  |  |
| `close_reason` | string or null |  | at most 2000 characters |
| `source` | `manual`, `web_form`, `import`, `email`, `api` or null |  |  |
| `source_campaign_id` | string (uuid) or null |  |  |
| `custom` | object |  |  |
| `source_system` | string or null |  | 1–100 characters |
| `source_id` | string or null |  | 1–500 characters |
| `contacts` | array of object |  | at most 50 items |
| `contacts[].contact_id` | string (uuid) | yes |  |
| `contacts[].role` | string or null |  | at most 200 characters |
| `contacts[].is_primary` | boolean |  |  |

### Response 201

Returns: [Opportunity](/api/reference/objects.md#opportunity).

Errors are problem details with a stable `code`: see [Errors](/errors.md).

## Get a deal

`GET https://staging-api.naruskacrm.com/v1/opportunities/{id}`

`include` adds `children` (emails, phones, addresses, affiliations, deal contacts, attendees), `tags` and `related` (the first 10 of each related list), so a record page loads in one request.

### Parameters

| Parameter | In | Type | Required | Notes |
| --- | --- | --- | --- | --- |
| `id` | path | string (uuid) | yes |  |
| `include` | query | string |  | at most 100 characters |

### Response 200

| Field | Type | Always present | Notes |
| --- | --- | --- | --- |
| `id` | string (uuid) | yes |  |
| `company_id` | string (uuid) | yes |  |
| `created_at` | string (date-time) | yes |  |
| `updated_at` | string (date-time) | yes |  |
| `created_by` | string (uuid) or null | yes |  |
| `updated_by` | string (uuid) or null | yes |  |
| `deleted_at` | string (date-time) or null | yes |  |
| `deleted_by` | string (uuid) or null | yes |  |
| `name` | string | yes |  |
| `account_id` | string (uuid) or null | yes |  |
| `account_name` | string or null |  |  |
| `pipeline_id` | string (uuid) | yes |  |
| `pipeline_name` | string |  |  |
| `stage_id` | string (uuid) | yes |  |
| `stage_api_key` | string |  |  |
| `stage_name` | string |  |  |
| `stage_category` | `open`, `won`, `lost` |  |  |
| `primary_contact_id` | string (uuid) or null |  |  |
| `primary_contact_name` | string or null |  |  |
| `owner_user_id` | string (uuid) or null | yes |  |
| `owner_user_name` | string or null |  |  |
| `owner_team_id` | string (uuid) or null | yes |  |
| `owner_team_name` | string or null |  |  |
| `owner_name` | string or null |  |  |
| `amount` | number or null | yes |  |
| `amount_source` | string or null | yes |  |
| `currency` | string | yes |  |
| `base_currency` | string |  |  |
| `amount_base` | number or null |  |  |
| `expected_close_date` | string (date) or null | yes |  |
| `closed_at` | string (date-time) or null | yes |  |
| `close_rate` | number or null | yes |  |
| `close_reason` | string or null | yes |  |
| `source` | string or null | yes |  |
| `source_campaign_id` | string (uuid) or null | yes |  |
| `source_campaign_name` | string or null |  |  |
| `custom` | object | yes |  |
| `custom_labels` | [CustomLabels](/api/reference/objects.md#customlabels) |  |  |
| `source_system` | string or null | yes |  |
| `source_id` | string or null | yes |  |
| `children` | object |  |  |
| `tags` | array of [Tag](/api/reference/objects.md#tag) |  |  |
| `related` | object |  |  |

Errors are problem details with a stable `code`: see [Errors](/errors.md).

## Update a deal

`PATCH https://staging-api.naruskacrm.com/v1/opportunities/{id}`

JSON merge patch: send only the fields to change. custom is merged per key; a null value removes a key.

### Parameters

| Parameter | In | Type | Required | Notes |
| --- | --- | --- | --- | --- |
| `id` | path | string (uuid) | yes |  |

### Request body

| Field | Type | Required | Notes |
| --- | --- | --- | --- |
| `name` | string |  | 1–200 characters |
| `account_id` | string (uuid) or null |  |  |
| `pipeline_id` | string (uuid) |  |  |
| `stage_id` | string (uuid) |  |  |
| `stage` | string |  | at most 63 characters |
| `owner_user_id` | string (uuid) or null |  |  |
| `owner_team_id` | string (uuid) or null |  |  |
| `amount` | number or null |  | 0–10000000000000000 |
| `amount_source` | `estimate`, `quote` or null |  |  |
| `currency` | string |  |  |
| `expected_close_date` | string (date) or null |  |  |
| `close_reason` | string or null |  | at most 2000 characters |
| `source` | `manual`, `web_form`, `import`, `email`, `api` or null |  |  |
| `source_campaign_id` | string (uuid) or null |  |  |
| `custom` | object |  |  |
| `source_system` | string or null |  | 1–100 characters |
| `source_id` | string or null |  | 1–500 characters |

### Response 200

Returns: [Opportunity](/api/reference/objects.md#opportunity).

Errors are problem details with a stable `code`: see [Errors](/errors.md).

## Delete a deal (soft delete)

`DELETE https://staging-api.naruskacrm.com/v1/opportunities/{id}`

Soft delete (admins only). The record and its children are kept for 30 days and can be restored.

### Parameters

| Parameter | In | Type | Required | Notes |
| --- | --- | --- | --- | --- |
| `id` | path | string (uuid) | yes |  |

### Response 204

Done.
No body.

Errors are problem details with a stable `code`: see [Errors](/errors.md).

## Restore a deleted deal

`POST https://staging-api.naruskacrm.com/v1/opportunities/{id}/restore`

Admins only. Children and links deleted with the record come back with it.

### Parameters

| Parameter | In | Type | Required | Notes |
| --- | --- | --- | --- | --- |
| `id` | path | string (uuid) | yes |  |

### Response 200

Returns: [Opportunity](/api/reference/objects.md#opportunity).

Errors are problem details with a stable `code`: see [Errors](/errors.md).

## List a deal's contacts

`GET https://staging-api.naruskacrm.com/v1/opportunities/{id}/contacts`

### Parameters

| Parameter | In | Type | Required | Notes |
| --- | --- | --- | --- | --- |
| `id` | path | string (uuid) | yes |  |

### Response 200

| Field | Type | Always present | Notes |
| --- | --- | --- | --- |
| `data` | array of [OpportunityContact](/api/reference/objects.md#opportunitycontact) | yes |  |

Errors are problem details with a stable `code`: see [Errors](/errors.md).

## Add a deal contact

`POST https://staging-api.naruskacrm.com/v1/opportunities/{id}/contacts`

### Parameters

| Parameter | In | Type | Required | Notes |
| --- | --- | --- | --- | --- |
| `id` | path | string (uuid) | yes |  |

### Request body

| Field | Type | Required | Notes |
| --- | --- | --- | --- |
| `contact_id` | string (uuid) | yes |  |
| `role` | string or null |  | at most 200 characters |
| `is_primary` | boolean |  |  |

### Response 201

Returns: [OpportunityContact](/api/reference/objects.md#opportunitycontact).

Errors are problem details with a stable `code`: see [Errors](/errors.md).

## Update a deal contact

`PATCH https://staging-api.naruskacrm.com/v1/opportunities/{id}/contacts/{childId}`

### Parameters

| Parameter | In | Type | Required | Notes |
| --- | --- | --- | --- | --- |
| `id` | path | string (uuid) | yes |  |
| `childId` | path | string (uuid) | yes |  |

### Request body

| Field | Type | Required | Notes |
| --- | --- | --- | --- |
| `role` | string or null |  | at most 200 characters |
| `is_primary` | boolean |  |  |

### Response 200

Returns: [OpportunityContact](/api/reference/objects.md#opportunitycontact).

Errors are problem details with a stable `code`: see [Errors](/errors.md).

## Remove a deal contact

`DELETE https://staging-api.naruskacrm.com/v1/opportunities/{id}/contacts/{childId}`

### Parameters

| Parameter | In | Type | Required | Notes |
| --- | --- | --- | --- | --- |
| `id` | path | string (uuid) | yes |  |
| `childId` | path | string (uuid) | yes |  |

### Response 204

Done.
No body.

Errors are problem details with a stable `code`: see [Errors](/errors.md).

## A pipeline's board

`GET https://staging-api.naruskacrm.com/v1/pipelines/{id}/board`

Per live stage: count, sum of amount_base (the company's base currency) and the first cards (sorted by expected_close_date). Filters: owner (me or a user id), tag, close date range, q. For more cards of a stage, list opportunities with stage=<stage_id>, sort=expected_close_date and the stage's next_cursor.

### Parameters

| Parameter | In | Type | Required | Notes |
| --- | --- | --- | --- | --- |
| `id` | path | string (uuid) | yes |  |
| `owner` | query | `me` or string (uuid) |  |  |
| `tag` | query | string |  | at most 100 characters |
| `close_date_from` | query | string (date) |  |  |
| `close_date_to` | query | string (date) |  |  |
| `q` | query | string |  | 1–200 characters |
| `cards` | query | integer or null |  | 0–50, default `50` |

### Response 200

| Field | Type | Always present | Notes |
| --- | --- | --- | --- |
| `pipeline_id` | string (uuid) | yes |  |
| `base_currency` | string | yes |  |
| `stages` | array of object | yes |  |
| `stages[].stage_id` | string (uuid) | yes |  |
| `stages[].api_key` | string | yes |  |
| `stages[].name` | string | yes |  |
| `stages[].category` | `open`, `won`, `lost` | yes |  |
| `stages[].sort_order` | number | yes |  |
| `stages[].count` | number | yes |  |
| `stages[].amount_base_sum` | number | yes |  |
| `stages[].cards` | array of [Opportunity](/api/reference/objects.md#opportunity) | yes |  |
| `stages[].next_cursor` | string or null | yes |  |

Errors are problem details with a stable `code`: see [Errors](/errors.md).

