# Update Opportunities

> Source: https://truto.one/docs/api-reference/unified-crm-api/opportunities/update/

`PATCH /unified/crm/opportunities/{id}`

Resource: **Opportunities** · API: **Unified CRM API**

## Supported integrations

Affinity, Attio, Capsule, Close, Freshsales, Highlevel, HubSpot, Insightly, Keap, Monday CRM, OnePageCRM, Outreach, Pipedrive, Pipeliner, Planhat, Salesflare, Salesforce, Teamleader, Zendesk Sell, Zoho CRM

## Path parameters

- **`id`** _(string, required)_
  The ID of the resource.

## Query parameters

- **`integrated_account_id`** _(string, required)_
  The ID of the integrated account to use for the request.
- **`truto_response_format`** _(string)_
  The format of the response. - `unified` returns the response with unified mappings applied. - `raw` returns the unprocessed, raw response from the remote API. - `normalized` applies the unified mappings and returns the data in a normalized format. - `stream` returns the response as a stream, which is ideal for transmitting large datasets, files, or binary data. Using streaming mode helps to efficiently handle large payloads or real-time data flows without requiring the entire data to be buffered in memory. Defaults to `unified`.
  Allowed: `unified`, `raw`, `normalized`, `stream`
- **`truto_ignore_remote_data`** _(boolean)_
  Excludes the `remote_data` attribute from the response.
- **`truto_exclude_fields`** _(array<string>)_
  Array of fields to exclude from the response.
- **`remote_query`** _(object)_
  Query parameters to pass to the underlying API without any transformations. Refer [this guide](https://truto.one/docs/api-reference/overview/querying#remote-query-parameters) to see how to structure the query parameters.

## Request body

- **`name`** _(string)_
  The opportunity's name
- **`account`** _(object)_
  The opportunity's account
  - **`id`** _(string, required)_
    The account's unique identifier
- **`contact`** _(array<object>)_
  The opportunity's contacts
  - **`id`** _(string, required)_
    The contact's unique identifier
- **`status`** _(string)_
  The opportunity's status
  Allowed: `lead`, `in_progress`, `won`, `lost`, `open`, `lost`, `won`, `abandoned`, `all`, `open`, `won`, `suspended` (+6 more)
- **`amount`** _(number)_
  The opportunity's amount
- **`owner`** _(object)_
  The opportunity's owner
  - **`id`** _(string, required)_
    The opportunity's owner's unique identifier
- **`custom_fields`** _(object)_
  Custom fields to be set on the contact. The custom_fields object will be a key-value pair, where the key will be the `name` attribute of the custom field found in the response of https://truto.one/docs/api-reference/unified-crm-api/fields/list endpoint.
- **`description`** _(string)_
  The opportunity's description
- **`stage`** _(object)_
  The opportunity's stage
  - **`id`** _(string)_
    The stage's unique identifier
  - **`name`** _(string)_
    The stage's name
- **`currency`** _(string)_
  The amount attribute's currency
- **`tags`** _(array<object>)_
  The opportunity's tags
  - **`id`** _(string)_
    The tag's unique identifier
  - **`name`** _(string)_
    The tag's name
- **`close_date`** _(string)_
  The date and time of the opportunity's close date
- **`created_at`** _(string)_
  The date and time of the opportunity's creation
- **`close_time`** _(unknown)_
- **`remote_data`** _(object)_
  Any additional data that should be passed as part of the request body. This data is not transformed by Truto and is passed as is to the remote API.

## Response body

- **`id`** _(string, required)_
  The opportunity's unique identifier
- **`name`** _(string)_
  The opportunity's name
- **`description`** _(string)_
  The opportunity's description
- **`amount`** _(number)_
  The opportunity's amount
- **`currency`** _(string)_
  The amount attribute's currency
- **`owner`** _(object)_
  The opportunity's owner
  - **`id`** _(string)_
    The opportunity's owner's unique identifier
- **`account`** _(object)_
  The opportunity's account
  - **`id`** _(string)_
    The account's unique identifier
- **`contact`** _(array<object>)_
  The opportunity's contacts
  - **`id`** _(string)_
    The contact's unique identifier
- **`stage`** _(object)_
  The opportunity's stage
  - **`id`** _(string)_
    The stage's unique identifier
  - **`name`** _(string)_
    The stage's name
- **`status`** _(string)_
  The opportunity's status
- **`tags`** _(array<object>)_
  The opportunity's tags
  - **`id`** _(string)_
    The tag's unique identifier
  - **`name`** _(string)_
    The tag's name
- **`custom_fields`** _(object)_
  All the custom fields present on the opportunity
- **`last_activity_at`** _(string)_
  The date and time of the opportunity's last activity
- **`close_date`** _(string)_
  The date and time of the opportunity's close date
- **`created_at`** _(string)_
  The date and time of the opportunity's creation
- **`updated_at`** _(string)_
  The date and time of the opportunity's last update
- **`urls`** _(array<object>)_
  The opportunity's urls
  - **`url`** _(string)_
    The opportunity's URL
  - **`type`** _(string)_
    The opportunity's URL type
- **`remote_data`** _(object)_
  Raw data returned from the remote API call.

## Code examples

### curl

```bash
curl -X PATCH 'https://api.truto.one/unified/crm/opportunities/{id}?integrated_account_id=<integrated_account_id>' \
  -H 'Authorization: Bearer <your_api_token>' \
  -H 'Content-Type: application/json' \
  -d '{
  "name": "your_name",
  "account": {},
  "contact": [],
  "status": "lead",
  "amount": 0,
  "owner": {},
  "custom_fields": "{\n  \"custom_field_name_1\": \"foo\",\n  \"custom_field_name_2\": \"bar\"\n}\n",
  "description": "your_description",
  "stage": {},
  "currency": "your_currency",
  "tags": [],
  "close_date": "your_close_date",
  "created_at": "your_created_at",
  "remote_data": {}
}'
```

### JavaScript

```javascript
const integratedAccountId = '<integrated_account_id>';

const body = {
  "name": "your_name",
  "account": {},
  "contact": [],
  "status": "lead",
  "amount": 0,
  "owner": {},
  "custom_fields": "{\n  \"custom_field_name_1\": \"foo\",\n  \"custom_field_name_2\": \"bar\"\n}\n",
  "description": "your_description",
  "stage": {},
  "currency": "your_currency",
  "tags": [],
  "close_date": "your_close_date",
  "created_at": "your_created_at",
  "remote_data": {}
};

const response = await fetch(`https://api.truto.one/unified/crm/opportunities/{id}?integrated_account_id=${integratedAccountId}`, {
  method: 'PATCH',
  headers: {
    'Authorization': 'Bearer <your_api_token>',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify(body),
});

const data = await response.json();
console.log(data);
```

### Python

```python
import requests

url = "https://api.truto.one/unified/crm/opportunities/{id}"
headers = {
    "Authorization": "Bearer <your_api_token>",
    "Content-Type": "application/json",
}
params = {
    "integrated_account_id": "<integrated_account_id>"
}
payload = {
    "name": "your_name",
    "account": {},
    "contact": [],
    "status": "lead",
    "amount": 0,
    "owner": {},
    "custom_fields": "{\n  \"custom_field_name_1\": \"foo\",\n  \"custom_field_name_2\": \"bar\"\n}\n",
    "description": "your_description",
    "stage": {},
    "currency": "your_currency",
    "tags": [],
    "close_date": "your_close_date",
    "created_at": "your_created_at",
    "remote_data": {}
}

response = requests.patch(url, headers=headers, params=params, json=payload)
print(response.json())
```

### Truto TS SDK

```typescript
import Truto from '@truto/truto-ts-sdk';

const truto = new Truto({
  token: '<your_api_token>',
});

const result = await truto.unifiedApi.update(
  'crm',
  'opportunities',
  '<resource_id>',
  {
  "name": "your_name",
  "account": {},
  "contact": [],
  "status": "lead",
  "amount": 0,
  "owner": {},
  "custom_fields": "{\n  \"custom_field_name_1\": \"foo\",\n  \"custom_field_name_2\": \"bar\"\n}\n",
  "description": "your_description",
  "stage": {},
  "currency": "your_currency",
  "tags": [],
  "close_date": "your_close_date",
  "created_at": "your_created_at",
  "remote_data": {}
},
  { integrated_account_id: '<integrated_account_id>' }
);

console.log(result);
```

### Truto Python SDK

```python
import asyncio
from truto_python_sdk import TrutoApi

truto_api = TrutoApi(token="<your_api_token>")

async def main():
    result = await truto_api.unified_api.update(
        "crm",
        "opportunities",
        "<resource_id>",
        {
        "name": "your_name",
        "account": {},
        "contact": [],
        "status": "lead",
        "amount": 0,
        "owner": {},
        "custom_fields": "{\n  \"custom_field_name_1\": \"foo\",\n  \"custom_field_name_2\": \"bar\"\n}\n",
        "description": "your_description",
        "stage": {},
        "currency": "your_currency",
        "tags": [],
        "close_date": "your_close_date",
        "created_at": "your_created_at",
        "remote_data": {}
},
        {"integrated_account_id": "<integrated_account_id>"}
    )
    print(result)

asyncio.run(main())
```
