> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cria.chat/llms.txt
> Use this file to discover all available pages before exploring further.

# Create opportunities

> Create or update one opportunity or a batch of up to 100 opportunities.

```bash Single opportunity theme={null}
curl --request POST \
  --url "https://app.cria.chat/api/v1/accounts/10/crm/inbox/25/kanban" \
  --header "api_access_token: YOUR_API_ACCESS_TOKEN" \
  --header "Accept: application/json" \
  --header "Content-Type: application/json" \
  --include \
  --data-raw '{
  "origin": "partner-crm",
  "opportunities": [
    {
      "external_id": "deal-123",
      "external_url": "https://crm.example.com/deals/123",
      "stage_id": 10,
      "lead": {
        "name": "Mary Johnson",
        "mobile_phone": "+5511999999999",
        "email": "mary@example.com",
        "customer_id": "customer-456"
      },
      "opportunity": {
        "title": "Motorcycle purchase",
        "value": 15000,
        "currency": "BRL",
        "source": "website",
        "qualified": true
      }
    }
  ]
}'
```

```bash Batch import theme={null}
curl --request POST \
  --url "https://app.cria.chat/api/v1/accounts/10/crm/inbox/25/kanban" \
  --header "api_access_token: YOUR_API_ACCESS_TOKEN" \
  --header "Accept: application/json" \
  --header "Content-Type: application/json" \
  --include \
  --data-raw '{
  "origin": "partner-crm",
  "opportunities": [
    {
      "external_id": "deal-123",
      "external_url": "https://crm.example.com/deals/123",
      "stage_id": 10,
      "lead": {
        "name": "Mary Johnson",
        "mobile_phone": "+5511999999999",
        "email": "mary@example.com",
        "customer_id": "customer-456"
      },
      "opportunity": {
        "title": "Motorcycle purchase",
        "value": 15000,
        "currency": "BRL",
        "source": "website",
        "qualified": true
      }
    },
    {
      "external_id": "deal-124",
      "stage_id": 11,
      "lead": {
        "name": "Charles Brown",
        "email": "charles@example.com"
      },
      "opportunity": {
        "title": "Service appointment"
      }
    }
  ]
}'
```

```json 201 Created theme={null}
{
  "data": {
    "origin": "partner-crm",
    "imported": 1,
    "results": [
      {
        "contact": "created",
        "matched_by": [],
        "contact_id": 456,
        "name_mismatch": false,
        "existing_name": "Mary Johnson",
        "imported_name": "Mary Johnson",
        "opportunity": "created",
        "opportunity_id": 123,
        "origin": "partner-crm",
        "external_id": "deal-123",
        "index": 0
      }
    ]
  }
}
```

```json 401 Unauthorized theme={null}
{
  "error": "Invalid Access Token"
}
```

```json 404 Not Found theme={null}
{
  "error": "inbox_id is invalid or inaccessible"
}
```

Create one opportunity or import a batch into an inbox's Kanban boards. Send the same `opportunities` array for both operations, with one item for an individual request or up to 100 items for a batch.

## cURL examples

The request panel includes complete commands for single-opportunity and batch imports. Replace `YOUR_API_ACCESS_TOKEN`, account ID `10`, inbox ID `25`, and stage IDs with values from your account. Stage IDs identify Kanban columns.

The cURL commands use Bash syntax. `--include` prints the HTTP status and response headers along with the JSON body.

## Authentication

Send a user or AgentBot API access token in the request header:

```http theme={null}
api_access_token: YOUR_API_ACCESS_TOKEN
Content-Type: application/json
```

The token must have access to the account, inbox, and destination stages. A session login alone does not authorize this endpoint. Stages with an enabled GIA campaign entry action require administrator privileges; AgentBot tokens are treated as administrators for Kanban access.

## Path parameters

| Field | Required | Description |
| - | - | - |
| `account_id` | Yes | CriaChat account ID. |
| `inbox_id` | Yes | ID of an inbox accessible to the token. All destination stages must belong to this inbox. |

## Common fields

| Field | Required | Description |
| - | - | - |
| `origin` | No | Shared source identifier for the batch, such as `partner-crm`. Keep it stable across requests to recognize previously imported opportunities. Generated automatically when omitted. |
| `opportunities` | Yes | Array containing 1 to 100 opportunity objects. |

Each item in `opportunities` accepts:

| Field | Required | Description |
| - | - | - |
| `external_id` | Yes | Non-empty identifier in the source system. |
| `stage_id` | Yes | CriaChat Kanban column ID for the destination stage. |
| `lead` | Yes | Contact details; `lead.name` is required. |
| `external_url` | No | Link to the record in the source system. |
| `opportunity` | No | Commercial details listed below. |
| `profile` | No | Object containing additional profile data. |
| `consents` | No | Object containing consent data. |
| `record` | No | Object containing additional record data. |
| `comment_history` | No | Array of objects with `created_at` and `comment`. Use ISO 8601 timestamps. |

Send `origin` at the top level, rather than inside individual items.

### Lead fields

| Field | Required | Description |
| - | - | - |
| `name` | Yes | Contact name. |
| `customer_id` | No | External customer ID, stored as a contact custom attribute. It is not used to match contacts. |
| `mobile_phone` | No | Contact phone number, including country code. Takes precedence over `phone`. |
| `phone` | No | Alternative phone field when `mobile_phone` is absent. |
| `email` | No | Contact email address. |

Contacts are matched by normalized phone number or case-insensitive email. If neither matches, a contact is created. If phone and email match different contacts, a new contact is created without those identifiers and a conflict is recorded. Existing contact names and identifiers are preserved.

### Opportunity fields

| Fields | Description |
| - | - |
| `title` | Opportunity title, up to 255 characters. Falls back to `type` when `title` is omitted. |
| `value`, `currency` | Non-negative monetary value and a currency code containing three uppercase letters, such as `BRL`. |
| `product`, `product_code`, `product_item_id` | Product name, catalog code, or CriaChat product item ID. |
| `service`, `service_code`, `service_item_id` | Service name, catalog code, or CriaChat service item ID. |
| `product_version`, `preferred_color` | Product version and preferred color. |
| `type`, `status` | External opportunity type and status. `status` is stored as the external status; it does not mark the CriaChat opportunity as won or lost. |
| `source`, `sub_source`, `conversion_point` | Acquisition and conversion details. |
| `current_motorcycle`, `current_vehicle` | Current vehicle details. |
| `qualified`, `owner` | Qualification flag and external owner. `owner` does not assign a CriaChat agent. |
| `first_contact_time_minutes`, `days_without_update` | External contact and update metrics. |
| `last_customer_contact_at` | Last customer contact timestamp. Use ISO 8601. |
| `financing` | Object containing financing data. |

Product and service resolution follows the board's catalog settings. Restricted boards require matching active catalog items; boards configured to register imported items can create or reactivate items. When `value` is omitted, an available service or product catalog value may be applied.

## Create one opportunity

Minimum payload:

```json theme={null}
{
  "origin": "partner-crm",
  "opportunities": [
    {
      "external_id": "deal-123",
      "stage_id": 10,
      "lead": {
        "name": "Mary Johnson"
      }
    }
  ]
}
```

## Create a batch

```json theme={null}
{
  "origin": "partner-crm",
  "opportunities": [
    {
      "external_id": "deal-123",
      "external_url": "https://crm.example.com/deals/123",
      "stage_id": 10,
      "lead": {
        "name": "Mary Johnson",
        "mobile_phone": "+5511999999999",
        "email": "mary@example.com",
        "customer_id": "customer-456"
      },
      "opportunity": {
        "title": "Motorcycle purchase",
        "value": 15000,
        "currency": "BRL",
        "source": "website",
        "qualified": true
      }
    },
    {
      "external_id": "deal-124",
      "stage_id": 11,
      "lead": {
        "name": "Charles Brown",
        "email": "charles@example.com"
      },
      "opportunity": {
        "title": "Service appointment"
      }
    }
  ]
}
```

## Updates and retries

An existing import is identified by account, Kanban board, provider, `origin`, and `external_id`. Sending the same identity updates the existing opportunity instead of creating another one. Changing boards or `origin` creates a separate import identity.

> [!NOTE]
>
> Keep `origin` stable when retrying requests. If omitted, a new timestamp-based origin is generated for each request, so repeated requests can create additional opportunities.

Updates preserve opportunity fields marked as internally edited. A recognized reimport can also change the stage within the board and unarchive the opportunity. Use [Change opportunity stage](https://docs.cria.chat/api-reference/crm/opportunities/change-stage.md) for stage transitions that apply sale and loss rules.

## Validation rules

* The batch must contain 1 to 100 items.
* Every item requires `external_id`, `stage_id`, and `lead.name`.
* Unknown fields are rejected at the top level, in each item, in `lead`, in `opportunity`, and in comment entries. The documented free-form objects preserve additional properties.
* `opportunity.title` cannot exceed 255 characters.
* A provided non-null `opportunity.value` must be a non-negative number.
* A provided `opportunity.currency` must contain exactly three uppercase letters.
* The batch is processed in a single transaction. If an item fails, the batch's database changes are rolled back.

## Response models

### 201 Created

Returns **201 Created** for successful requests, including requests that update existing imports. Example for a single new opportunity:

```json theme={null}
{
  "data": {
    "origin": "partner-crm",
    "imported": 1,
    "results": [
      {
        "contact": "created",
        "matched_by": [],
        "contact_id": 456,
        "name_mismatch": false,
        "existing_name": "Mary Johnson",
        "imported_name": "Mary Johnson",
        "opportunity": "created",
        "opportunity_id": 123,
        "origin": "partner-crm",
        "external_id": "deal-123",
        "index": 0
      }
    ]
  }
}
```

`opportunity` is `created` or `updated`. `contact` can be `created`, `matched`, `already_linked`, or `conflict`. `index` is the zero-based position in the submitted array. Catalog resolution may also return `product` or `service` objects with `id` and `status` (`matched`, `created`, or `reactivated`). Store `opportunity_id` to use the stage-change endpoint.

| Field | Type | Description |
| - | - | - |
| `data.origin` | string | Shared import origin. |
| `data.imported` | integer | Number of items processed, including updates. |
| `data.results` | array of objects | One result per submitted item. |
| `data.results[].opportunity_id` | integer | Internal CriaChat opportunity ID. |
| `data.results[].opportunity` | string | `created` or `updated`. |
| `data.results[].contact` | string | `created`, `matched`, `already_linked`, or `conflict`. |
| `data.results[].contact_id` | integer | Linked contact ID. |
| `data.results[].matched_by` | array of strings | Contact matching identifiers, such as `phone` or `email`. |
| `data.results[].name_mismatch` | boolean | Whether the imported name differs from the linked contact name. |
| `data.results[].existing_name` | string | Linked contact name. |
| `data.results[].imported_name` | string | Submitted contact name. |
| `data.results[].origin` | string | Origin used for this import identity. |
| `data.results[].external_id` | string | Source system opportunity ID. |
| `data.results[].index` | integer | Zero-based item position in the request. |
| `data.results[].product`, `data.results[].service` | object | Optional catalog result with an integer `id` and string `status`. |

### 401 Unauthorized

The API access token is missing or invalid. Account access failures and suspended accounts can also return `401`, with a different `error` message.

```json theme={null}
{
  "error": "Invalid Access Token"
}
```

### 404 Not Found

The specified inbox is invalid or inaccessible. An invalid or inaccessible destination stage is reported as `422`, rather than this inbox error.

```json theme={null}
{
  "error": "inbox_id is invalid or inaccessible"
}
```

Both error examples use this model:

| Field | Type | Description |
| - | - | - |
| `error` | string | Reason the request failed. |

## Errors

| HTTP status | Meaning |
| - | - |
| `401` | Missing or invalid API access token, suspended account, or account access denied. |
| `404` | Inbox is invalid or inaccessible. |
| `422` | Invalid batch size, missing required fields, unsupported fields, inaccessible stage, catalog resolution failure, or model validation failure. |

Example validation error:

```json theme={null}
{
  "error": "opportunities[0].lead.name is required"
}
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.