> ## 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.

# Search Opportunities

> Search Opportunities based on combinations of advanced filters. Documentation Link - https://doc.clickup.com/8631005/d/h/87cpx-424216/7bf11bc9b94f80f

Search Opportunities based on combinations of advanced filters. Documentation Link - [https://doc.clickup.com/8631005/d/h/87cpx-424216/7bf11bc9b94f80f](https://doc.clickup.com/8631005/d/h/87cpx-424216/7bf11bc9b94f80f)

```http
POST https://services.leadconnectorhq.com/opportunities/search
```

## Authorization

| Name | Type | Required | Example | Description |
| --- | --- | --- | --- | --- |
| `Authorization` | string | Yes |   | Bearer token generated from the Leadway portal. See [Authentication](https://developers.leadwaycrm.com/authentication). |
| `Version` | string | Yes | `2021-07-28` | API version. |

## Body

| Name | Type | Required | Example | Description |
| --- | --- | --- | --- | --- |
| `locationId` | string | Yes | `i2SpAtBVHSVea1sL6oah` | Account Id |
| `query` | string | Yes |   |   |
| `limit` | number | Yes |   |   |
| `page` | number | Yes |   |   |
| `searchAfter` | string\[\] | Yes |   |   |

- `additionalDetails` (object, required)

  - `notes` (boolean, required)
  - `tasks` (boolean, required)
  - `calendarEvents` (boolean, required)
  - `unReadConversations` (boolean, required)

## Responses

**200 - Successful response**

- `opportunities` (object\[\])

  - `id` (string): Example: `yWQobCRIhRguQtD2llvk`

  - `name` (string): Example: `testing`

  - `monetaryValue` (number): Example: `500`

  - `pipelineId` (string): Example: `VDm7RPYC2GLUvdpKmBfC`

  - `pipelineStageId` (string): Example: `e93ba61a-53b3-45e7-985a-c7732dbcdb69`

  - `assignedTo` (string): Example: `zT46WSCPbudrq4zhWMk6`

  - `status` (string): Example: `open`

  - `source` (string)

  - `lastStatusChangeAt` (string): Example: `2021-08-03T04:55:17.355Z`

  - `lastStageChangeAt` (string): Example: `2021-08-03T04:55:17.355Z`

  - `lastActionDate` (string): Example: `2021-08-03T04:55:17.355Z`

  - `indexVersion` (string): Example: `1`

  - `createdAt` (string): Example: `2021-08-03T04:55:17.355Z`

  - `updatedAt` (string): Example: `2021-08-03T04:55:17.355Z`

  - `contactId` (string): Example: `zT46WSCPbudrq4zhWMk6`

  - `locationId` (string): Example: `zT46WSCPbudrq4zhW`

  - `contact` (object)

    - `id` (string): Example: `byMEV0NQinDhq8ZfiOi2`
    - `name` (string): Example: `John Deo`
    - `companyName` (string): Example: `Tesla Inc`
    - `email` (string): Example: `john@deo.com`
    - `phone` (string): Example: `+1202-555-0107`
    - `tags` (string\[\])

  - `notes` (array\[\])

  - `tasks` (array\[\])

  - `calendarEvents` (array\[\])

  - `lostReasonId` (string): Example: `zT46WSCPbudrq4zhWMk6`

  - `customFields` (object\[\])

    - `id` (string, required): Example: `MgobCB14YMVKuE4Ka8p1`
    - `fieldValue` (object, required): The value of the custom field

  - `followers` (array\[\])

  - `externalObjectId` (string)

- `total` (number, required): Example: `100`

- `aggregations` (object)

```json
{
  "opportunities": [
    {
      "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": []
      },
      "notes": [
        []
      ],
      "tasks": [
        []
      ],
      "calendarEvents": [
        []
      ],
      "lostReasonId": "zT46WSCPbudrq4zhWMk6",
      "customFields": [
        {}
  // truncado: 10 lineas mas
}
```

**400 - Bad Request**

```json
{}
```

**401 - Unauthorized**

```json
{}
```

**422 - Unprocessable Entity**

```json
{}
```

## Example

```bash cURL
curl -X POST 'https://services.leadconnectorhq.com/opportunities/search' \
  -H 'Authorization: Bearer YOUR_TOKEN' \
  -H 'Version: 2021-07-28' \
  -H 'Content-Type: application/json' \
  -d '{
  "locationId": "i2SpAtBVHSVea1sL6oah",
  "query": "string",
  "limit": 0,
  "page": 0,
  "searchAfter": [
    "string"
  ],
  "additionalDetails": {
    "notes": true,
    "tasks": true,
    "calendarEvents": true,
    "unReadConversations": true
  }
}'
```

```javascript Node.js
const response = await fetch('https://services.leadconnectorhq.com/opportunities/search', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.LEADWAY_TOKEN}`,
    Version: '2021-07-28',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({"locationId": "i2SpAtBVHSVea1sL6oah", "query": "string", "limit": 0, "page": 0, "searchAfter": ["string"], "additionalDetails": {"notes": true, "tasks": true, "calendarEvents": true, "unReadConversations": true}}),
});
const data = await response.json();
```

```python Python
import os, requests
response = requests.request(
    'POST',
    'https://services.leadconnectorhq.com/opportunities/search',
    headers={
        'Authorization': f"Bearer {os.environ['LEADWAY_TOKEN']}",
        'Version': '2021-07-28',
        'Content-Type': 'application/json',
    },
    json={"locationId": "i2SpAtBVHSVea1sL6oah", "query": "string", "limit": 0, "page": 0, "searchAfter": ["string"], "additionalDetails": {"notes": true, "tasks": true, "calendarEvents": true, "unReadConversations": true}},
)
data = response.json()
```

```php PHP
<?php
$ch = curl_init('https://services.leadconnectorhq.com/opportunities/search');
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_HTTPHEADER => [
        'Authorization: Bearer ' . getenv('LEADWAY_TOKEN'),
        'Version: 2021-07-28',
        'Content-Type: application/json',
    ],
    CURLOPT_POSTFIELDS => json_encode({'locationId': 'i2SpAtBVHSVea1sL6oah', 'query': 'string', 'limit': 0, 'page': 0, 'searchAfter': ['string'], 'additionalDetails': {'notes': true, 'tasks': true, 'calendarEvents': true, 'unReadConversations': true}}),
]);
$data = json_decode(curl_exec($ch), true);
```
