# API - API call to create/update an Opportunity in CRM

## Create New Opportunity

<mark style="color:green;">`POST`</mark> `/crmopportunity?id=XX&i=instance`

`id = Funnel ID`

`i = instance_name (example: yourcompany)`

Full call: [https://sprinthub-api-master.sprinthub.app/crmopportunity?id=xx\&i=instance](https://sprinthub-api-master.sprinthub.app/crmopportunity?id=xx\&i=instancia)

\<Create a New Opportunity>

**Headers**

| Name          | Value              |
| ------------- | ------------------ |
| Content-Type  | `application/json` |
| Authorization | `Bearer <token>`   |
| apitoken      | XXXXXXXXX          |

**Body**

<table><thead><tr><th width="313">Name</th><th width="122">Type</th><th>Description</th></tr></thead><tbody><tr><td>title</td><td>string</td><td>Opportunity Title</td></tr><tr><td>value</td><td>number</td><td>Opportunity Value (numbers only)</td></tr><tr><td>crm_column</td><td>number</td><td>Column ID</td></tr><tr><td>lead_id</td><td>number</td><td>Lead ID</td></tr><tr><td>sequence</td><td>number</td><td>Sequence ID</td></tr><tr><td>status</td><td>string</td><td>open/gain/lost</td></tr><tr><td>expectedCloseDate</td><td>date</td><td>ISO Format: 2024-03-21T21:27:00.000Z</td></tr><tr><td>user</td><td>number</td><td>Responsible user ID</td></tr><tr><td><p>"fields": { </p><p>              "Field1": "Value1",</p><p>              "Field2": "Value2",</p><p>              "Field3": "Value3"</p><p>}</p></td><td>json object</td><td>CRM custom fields need to be inside a JSON Object named "fields"</td></tr><tr><td></td><td></td><td></td></tr></tbody></table>

**Response**

{% tabs %}
{% tab title="Codes on the side" %}

{% endtab %}

{% tab title="200" %}

````json
```json
{
    "id": 4534,
    "title": "Test Title",
    "value": 1,
    "crm_column": 159,
    "lead_id": 8473,
    "sequence": 3,
    "status": "open",
    "loss_reason": null,
    "gain_reason": null,
    "expectedCloseDate": null,
    "sale_channel": null,
    "campaign": null,
    "user": 156,
    "last_column_change": null,
    "last_status_change": null,
    "gain_date": null,
    "lost_date": null,
    "reopen_date": null,
    "await_column_approved": null,
    "await_column_approved_user": null,
    "reject_appro": null,
    "reject_appro_desc": null,
    "createDate": "2024-03-19T21:14:35.000Z",
    "updateDate": "2024-03-19T21:14:35.000Z",
    "sprint_permission": "all",
    "sprint_permission_user": null,
    "sprint_permission_department": null,
    "sprint_permission_users": [],
    "sprint_permission_users_select": [],
    "sprint_permission_departments": [],
    "sprint_permission_departments_select": [],
    "dataLead": {
        "_id": "645bab79d618593673238ccb",
        "id": 8473,
        "address": null,
        "canal_de_aquisicao": null,
        "channelRestrictions": {
            "instagram": {
                "mainChannel": false,
                "disabled": false,
                "frequencyValue": null,
                "frequencyUnits": "DAY"
            },
            "whatsapp": {
                "mainChannel": false,
                "disabled": false,
                "frequencyValue": null,
                "frequencyUnits": "DAY"
            },
            "email": {
                "mainChannel": true,
                "disabled": false,
                "frequencyValue": 5,
                "frequencyUnits": "DAY"
            },
            "messenger": {
                "mainChannel": false,
                "disabled": false,
                "frequencyValue": null,
                "frequencyUnits": "DAY"
            }
        },
        "city": "São Paulo",
        "company": 2582,
        "country": "Brazil",
        "createDate": "2023-05-10T14:34:33.187Z",
        "createdBy": null,
        "createdByName": "System",
        "email": "teste@teste.com",
        "firstname": "Teste",
        "instancedomain": "teste",
        "ips": [
            "187.34.47.xx",
            "177.76.52.xx",
            "189.0.84.xx",
            "179.193.100.xx",
            "177.62.4.xx",
            "187.89.87.xx"
        ],
        "lastActive": "2024-03-19T21:14:35.693Z",
        "lastname": "Silva",
        "link_instancia": null,
        "mobile": null,
        "owner": null,
        "phone": null,
        "photoUrl": null,
        "points": 30,
        "preferred_locale": "pt-BR",
        "senha_inicial": "teste123",
        "stage": null,
        "state": null,
        "timezone": "America/Sao_Paulo",
        "updatedBy": null,
        "updatedByName": null,
        "updatedDate": null,
        "utmTags": [],
        "whatsapp": "+5511xxxxxxx",
        "zipcode": null,
        "cargo": null,
        "departamento": null,
        "departmentAccess": [],
        "ignoreSubDepartments": false,
        "instance_active": "false",
        "lead_online": "false",
        "partner_instance": null,
        "userAccess": [],
        "createdByType": null
    },
    "dataCompany": {
        "_id": "645bab8axxxxd618565",
        "id": 2582,
        "cnpj": null,
        "companyaddress": null,
        "companyannualrevenue": null,
        "companycity": null,
        "companycountry": null,
        "companyemail": null,
        "companyindustry": null,
        "companyname": "Microsoft Inc",
        "companynemployees": null,
        "companyphone": null,
        "companystate": null,
        "companyzipcode": null,
        "createDate": "2023-05-10T14:34:50.537Z",
        "createdBy": null,
        "createdByName": "System",
        "dores": null,
        "owner": null,
        "photoUrl": null,
        "points": 0,
        "qtdeclientes": null,
        "updatedBy": null,
        "updatedByName": null,
        "updatedDate": null
    },
    "dataCompanyExtra": [
        {
            "id": 2582,
            "cnpj": null,
            "companyaddress": null,
            "companyannualrevenue": null,
            "companycity": null,
            "companycountry": null,
            "companyemail": null,
            "companyindustry": null,
            "companyname": "Microsoft Inc",
            "companynemployees": null,
            "companyphone": null,
            "companystate": null,
            "companyzipcode": null,
            "createDate": "2023-05-10T14:34:50.537Z",
            "createdBy": null,
            "createdByName": "System",
            "dores": null,
            "owner": null,
            "photoUrl": null,
            "points": 0,
            "qtdeclientes": null,
            "updatedBy": null,
            "updatedByName": null,
            "updatedDate": null
        }
    ],
    "fields": {
        "Field with Space": "9969887dddXXXXX"
    },
    "files": [],
    "filesData": []
}
```
````

{% endtab %}

{% tab title="400" %}

````json
```json
{
    "msg": "Error Message."
}
```
````

{% endtab %}
{% endtabs %}

***

## Update an Opportunity

<mark style="color:green;">`PUT`</mark> `/crmopportunity/XXX?id=XX&i=instance`

`XXX = Opportunity ID (number)`

`id = Funnel ID`

`i = instance_name (example: yourcompany)`

Full call: [https://sprinthub-api-master.sprinthub.app/crmopportunity/XXX?id=xx\&i=instance](https://sprinthub-api-master.sprinthub.app/crmopportunity/XXX?id=xx\&i=instancia)

\<Update an Opportunity>

**Headers**

| Name          | Value              |
| ------------- | ------------------ |
| Content-Type  | `application/json` |
| Authorization | `Bearer <token>`   |
| apitoken      | XXXXXXXXX          |

**Body**

<table><thead><tr><th width="313">Name</th><th width="122">Type</th><th>Description</th></tr></thead><tbody><tr><td>title</td><td>string</td><td>Opportunity Title</td></tr><tr><td>value</td><td>number</td><td>Opportunity Value (numbers only)</td></tr><tr><td>crm_column</td><td>number</td><td>Column ID</td></tr><tr><td>lead_id</td><td>number</td><td>Lead ID</td></tr><tr><td>sequence</td><td>number</td><td>Sequence ID</td></tr><tr><td>status</td><td>string</td><td>open/gain/lost</td></tr><tr><td>expectedCloseDate</td><td>date</td><td>ISO Format: 2024-03-21T21:27:00.000Z</td></tr><tr><td>user</td><td>number</td><td>Responsible user ID</td></tr><tr><td><p>"fields": { </p><p>              "Field1": "Value1",</p><p>              "Field2": "Value2",</p><p>              "Field3": "Value3"</p><p>}</p></td><td>json object</td><td>CRM custom fields need to be inside a JSON Object named "fields"</td></tr><tr><td></td><td></td><td></td></tr></tbody></table>

**Response**

{% tabs %}
{% tab title="200" %}

````json
```json
{
    "msg": "The opportunity has been updated.",
    "data": {
        "id": XXX,
        "other fields": ....
}
```
````

{% endtab %}

{% tab title="400" %}

```json
{
  "error": "Invalid request"
}
```

{% endtab %}
{% endtabs %}

## Examples using Postman

### Create Opportunity

<figure><img src="/files/334a74cab0590731d86a30335875218a94c410f0" alt=""><figcaption></figcaption></figure>

###

###

### Update an existing Opportunity:

<figure><img src="/files/c248d320d3828c8b157fe15856c832bc760b55e2" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.sprinthub.com/en/topics/api/api-api-call-to-create-update-opportunity-in-crm.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
