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

# Update Opportunity

> Update Opportunity

Update Opportunity

```http theme={null}
PUT https://services.leadconnectorhq.com/opportunities/{id}
```

## Autorización

<ParamField header="Authorization" type="string" required>
  Bearer token generado desde el portal Leadway. Ver [Autenticación](/authentication).
</ParamField>

<ParamField header="Version" type="string" required default="2021-07-28">
  Versión de la API.
</ParamField>

## Path parameters

<ParamField path="id" type="string" required default="yWQobCRIhRguQtD2llvk">
  Opportunity Id
</ParamField>

## Body

<ParamField body="pipelineId" type="string" default="bCkKGpDsyPP4peuKowkG">
  pipeline Id
</ParamField>

<ParamField body="name" type="string" default="First Opps" />

<ParamField body="pipelineStageId" type="string" default="7915dedc-8f18-44d5-8bc3-77c04e994a10" />

<ParamField body="status" type="string">
  Posibles valores: 'open', 'won', 'lost', 'abandoned', 'all'
</ParamField>

<ParamField body="monetaryValue" type="number" default="220" />

<ParamField body="assignedTo" type="string" default="082goXVW3lIExEQPOnd3" />

<ParamField body="customFields" type="object[]">
  Update custom fields to opportunities.
</ParamField>

## Respuestas

<Accordion title="200 - Successful response">
  <ResponseField name="opportunity" type="object">
    <Expandable title="propiedades">
      <ResponseField name="id" type="string" default="yWQobCRIhRguQtD2llvk" />

      <ResponseField name="name" type="string" default="testing" />

      <ResponseField name="monetaryValue" type="number" default="500" />

      <ResponseField name="pipelineId" type="string" default="VDm7RPYC2GLUvdpKmBfC" />

      <ResponseField name="pipelineStageId" type="string" default="e93ba61a-53b3-45e7-985a-c7732dbcdb69" />

      <ResponseField name="assignedTo" type="string" default="zT46WSCPbudrq4zhWMk6" />

      <ResponseField name="status" type="string" default="open" />

      <ResponseField name="source" type="string" default="" />

      <ResponseField name="lastStatusChangeAt" type="string" default="2021-08-03T04:55:17.355Z" />

      <ResponseField name="lastStageChangeAt" type="string" default="2021-08-03T04:55:17.355Z" />

      <ResponseField name="lastActionDate" type="string" default="2021-08-03T04:55:17.355Z" />

      <ResponseField name="indexVersion" type="string" default="1" />

      <ResponseField name="createdAt" type="string" default="2021-08-03T04:55:17.355Z" />

      <ResponseField name="updatedAt" type="string" default="2021-08-03T04:55:17.355Z" />

      <ResponseField name="contactId" type="string" default="zT46WSCPbudrq4zhWMk6" />

      <ResponseField name="locationId" type="string" default="zT46WSCPbudrq4zhW" />

      <ResponseField name="contact" type="object">
        <Expandable title="propiedades">
          <ResponseField name="id" type="string" default="byMEV0NQinDhq8ZfiOi2" />

          <ResponseField name="name" type="string" default="John Deo" />

          <ResponseField name="companyName" type="string" default="Tesla Inc" />

          <ResponseField name="email" type="string" default="john@deo.com" />

          <ResponseField name="phone" type="string" default="+1202-555-0107" />

          <ResponseField name="tags" type="string[]" />
        </Expandable>
      </ResponseField>

      <ResponseField name="notes" type="array[]" />

      <ResponseField name="tasks" type="array[]" />

      <ResponseField name="calendarEvents" type="array[]" />

      <ResponseField name="lostReasonId" type="string" default="zT46WSCPbudrq4zhWMk6" />

      <ResponseField name="customFields" type="object[]">
        <Expandable title="cada item">
          <ResponseField name="id" type="string" required default="MgobCB14YMVKuE4Ka8p1" />

          <ResponseField name="fieldValue" type="object" required>
            The value of the custom field
          </ResponseField>
        </Expandable>
      </ResponseField>

      <ResponseField name="followers" type="array[]" />

      <ResponseField name="externalObjectId" type="string" />
    </Expandable>
  </ResponseField>

  ```json theme={null}
  {
    "opportunity": {
      "id": "yWQobCRIhRguQtD2llvk",
      "name": "testing",
      "monetaryValue": 500,
      "pipelineId": "VDm7RPYC2GLUvdpKmBfC",
      "pipelineStageId": "e93ba61a-53b3-45e7-985a-c7732dbcdb69",
      "assignedTo": "zT46WSCPbudrq4zhWMk6",
      "status": "open",
      "source": "",
      "lastStatusChangeAt": "2021-08-03T04:55:17.355Z",
      "lastStageChangeAt": "2021-08-03T04:55:17.355Z",
      "lastActionDate": "2021-08-03T04:55:17.355Z",
      "indexVersion": 1,
      "createdAt": "2021-08-03T04:55:17.355Z",
      "updatedAt": "2021-08-03T04:55:17.355Z",
      "contactId": "zT46WSCPbudrq4zhWMk6",
      "locationId": "zT46WSCPbudrq4zhW",
      "contact": {
        "id": "byMEV0NQinDhq8ZfiOi2",
        "name": "John Deo",
        "companyName": "Tesla Inc",
        "email": "john@deo.com",
        "phone": "+1202-555-0107",
        "tags": [
          "string"
        ]
      },
      "notes": [
        []
      ],
      "tasks": [
        []
      ],
      "calendarEvents": [
        []
      ],
      "lostReasonId": "zT46WSCPbudrq4zhWMk6",
      "customFields": [
    // truncado: 10 lineas mas
  }
  ```
</Accordion>

<Accordion title="400 - Bad Request">
  ```json theme={null}
  {}
  ```
</Accordion>

<Accordion title="401 - Unauthorized">
  ```json theme={null}
  {}
  ```
</Accordion>

<Accordion title="422 - Unprocessable Entity">
  ```json theme={null}
  {}
  ```
</Accordion>

## Ejemplo

<CodeGroup>
  ```bash cURL theme={null}
  curl -X PUT 'https://services.leadconnectorhq.com/opportunities/YOUR_id' \
    -H 'Authorization: Bearer YOUR_TOKEN' \
    -H 'Version: 2021-07-28' \
    -H 'Content-Type: application/json' \
    -d '{
    "pipelineId": "bCkKGpDsyPP4peuKowkG",
    "name": "First Opps",
    "pipelineStageId": "7915dedc-8f18-44d5-8bc3-77c04e994a10",
    "status": "open",
    "monetaryValue": 220,
    "assignedTo": "082goXVW3lIExEQPOnd3",
    "customFields": []
  }'
  ```

  ```javascript Node.js theme={null}
  const response = await fetch('https://services.leadconnectorhq.com/opportunities/YOUR_id', {
    method: 'PUT',
    headers: {
      Authorization: `Bearer ${process.env.LEADWAY_TOKEN}`,
      Version: '2021-07-28',
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({"pipelineId": "bCkKGpDsyPP4peuKowkG", "name": "First Opps", "pipelineStageId": "7915dedc-8f18-44d5-8bc3-77c04e994a10", "status": "open", "monetaryValue": 220, "assignedTo": "082goXVW3lIExEQPOnd3", "customFields": []}),
  });
  const data = await response.json();
  ```

  ```python Python theme={null}
  import os, requests
  response = requests.request(
      'PUT',
      'https://services.leadconnectorhq.com/opportunities/YOUR_id',
      headers={
          'Authorization': f"Bearer {os.environ['LEADWAY_TOKEN']}",
          'Version': '2021-07-28',
          'Content-Type': 'application/json',
      },
      json={"pipelineId": "bCkKGpDsyPP4peuKowkG", "name": "First Opps", "pipelineStageId": "7915dedc-8f18-44d5-8bc3-77c04e994a10", "status": "open", "monetaryValue": 220, "assignedTo": "082goXVW3lIExEQPOnd3", "customFields": []},
  )
  data = response.json()
  ```

  ```php PHP theme={null}
  <?php
  $ch = curl_init('https://services.leadconnectorhq.com/opportunities/YOUR_id');
  curl_setopt_array($ch, [
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_CUSTOMREQUEST => 'PUT',
      CURLOPT_HTTPHEADER => [
          'Authorization: Bearer ' . getenv('LEADWAY_TOKEN'),
          'Version: 2021-07-28',
          'Content-Type: application/json',
      ],
      CURLOPT_POSTFIELDS => json_encode({'pipelineId': 'bCkKGpDsyPP4peuKowkG', 'name': 'First Opps', 'pipelineStageId': '7915dedc-8f18-44d5-8bc3-77c04e994a10', 'status': 'open', 'monetaryValue': 220, 'assignedTo': '082goXVW3lIExEQPOnd3', 'customFields': []}),
  ]);
  $data = json_decode(curl_exec($ch), true);
  ```
</CodeGroup>
