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

> Returns a list of all conversations matching the search criteria along with the sort and filter options selected.

Returns a list of all conversations matching the search criteria along with the sort and filter options selected.

```http
GET https://services.leadconnectorhq.com/conversations/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. |

## Query parameters

| Name | Type | Required | Example | Description |
| --- | --- | --- | --- | --- |
| `locationId` | string | Yes | `ABCHkzuJQ8ZMd4Te84GK` | Account Id |
| `contactId` | string | No | `9VEmS0si86GW6gXWU89b` | Contact Id |
| `assignedTo` | string | No | `ABCHkzuJQ8ZMd4Te84GK,fGiae4CHkzoskh8thsik` | User IDs that conversations are assigned to. Multiple IDs can be provided as comma-separated values. Use "unassigned" to fetch conversations not assigned to any user. |
| `followers` | string | No | `ABCHkzuJQ8ZMd4Te84GK,fGiae4CHkzoskh8thsik` | User IDs of followers to filter conversations by. Multiple IDs can be provided as comma-separated values. |
| `mentions` | string | No | `ABCHkzuJQ8ZMd4Te84GK,fGiae4CHkzoskh8thsik` | User Id of the mention. Multiple values are comma separated. |
| `query` | string | No | `Search string` | Search paramater as a string |
| `sort` | string | No | `asc` | Sort paramater - asc or desc |
| `startAfterDate` | any | No | `1600854` | Search to begin after the specified date - should contain the sort value of the last document |
| `id` | string | No | `ABCHkzuJQ8ZMd4Te84GK` | Id of the conversation |
| `limit` | number | No | `20` | Limit of conversations - Default is 20 |
| `lastMessageType` | string | No | `TYPE_SMS` | Type of the last message in the conversation as a string |
| `lastMessageAction` | string | No | `manual` | Action of the last outbound message in the conversation as string. |
| `lastMessageDirection` | string | No | `inbound` | Direction of the last message in the conversation as string. |
| `status` | string | No | `all` | The status of the conversation to be filtered - all, read, unread, starred |
| `sortBy` | string | No | `last_message_date` | The sorting of the conversation to be filtered as - manual messages or all messages |
| `sortScoreProfile` | string | No | `ABCHkzuJQ8ZMd4Te84GK` | Id of score profile on which sortBy.ScoreProfile should sort on |
| `scoreProfile` | string | No | `ABCHkzuJQ8ZMd4Te84GK` | Id of score profile on which conversations should get filtered out, works with scoreProfileMin & scoreProfileMax |
| `scoreProfileMin` | number | No | `ABCHkzuJQ8ZMd4Te84GK` | Minimum value for score |
| `scoreProfileMax` | number | No | `ABCHkzuJQ8ZMd4Te84GK` | Maximum value for score |
| `startDate` | number | No | `1640995200000` | Start date filter for dateAdded field (Unix timestamp in milliseconds) |
| `endDate` | number | No | `1672531199000` | End date filter for dateAdded field (Unix timestamp in milliseconds) |

## Responses

**200 - Successfully fetched the conversations**

- `conversations` (object\[\], required): The list of all conversations found for the given query

  - `id` (string, required): Conversation Id Example: `ABCHkzuJQ8ZMd4Te84GK`
  - `contactId` (string, required): Contact Id Example: `ABCHkzuJQ8ZMd4Te84GK`
  - `locationId` (string, required): Account Id Example: `ABCHkzuJQ8ZMd4Te84GK`
  - `lastMessageBody` (string, required): Content of the most recent message in the conversation Example: `This is a sample message body`
  - `lastMessageType` (string, required): Channel/type of the most recent message (SMS, Email, Call, etc) Possible values: 'TYPE\_CALL', 'TYPE\_SMS', 'TYPE\_RCS', 'TYPE\_EMAIL', 'TYPE\_SMS\_REVIEW\_REQUEST', 'TYPE\_WEBCHAT', 'TYPE\_SMS\_NO\_SHOW\_REQUEST', 'TYPE\_CAMPAIGN\_SMS', 'TYPE\_CAMPAIGN\_CALL', 'TYPE\_CAMPAIGN\_EMAIL', 'TYPE\_CAMPAIGN\_VOICEMAIL', 'TYPE\_FACEBOOK', 'TYPE\_CAMPAIGN\_FACEBOOK', 'TYPE\_CAMPAIGN\_MANUAL\_CALL', 'TYPE\_CAMPAIGN\_MANUAL\_SMS', 'TYPE\_GMB', 'TYPE\_CAMPAIGN\_GMB', 'TYPE\_REVIEW', 'TYPE\_INSTAGRAM', 'TYPE\_WHATSAPP', 'TYPE\_CUSTOM\_SMS', 'TYPE\_CUSTOM\_EMAIL', 'TYPE\_CUSTOM\_PROVIDER\_SMS', 'TYPE\_CUSTOM\_PROVIDER\_EMAIL', 'TYPE\_IVR\_CALL', 'TYPE\_ACTIVITY\_CONTACT', 'TYPE\_ACTIVITY\_INVOICE', 'TYPE\_ACTIVITY\_PAYMENT', 'TYPE\_ACTIVITY\_OPPORTUNITY', 'TYPE\_LIVE\_CHAT', 'TYPE\_LIVE\_CHAT\_INFO\_MESSAGE', 'TYPE\_ACTIVITY\_APPOINTMENT', 'TYPE\_FACEBOOK\_COMMENT', 'TYPE\_INSTAGRAM\_COMMENT', 'TYPE\_CUSTOM\_CALL', 'TYPE\_INTERNAL\_COMMENT', 'TYPE\_ACTIVITY\_EMPLOYEE\_ACTION\_LOG', 'TYPE\_TIKTOK', 'TYPE\_TIKTOK\_COMMENT', 'TYPE\_ACTIVITY\_WHATSAPP', 'TYPE\_FORM\_SUBMISSION', 'TYPE\_SMS\_REACTION' Example: `TYPE_SMS`
  - `type` (string, required): Primary channel/type of the conversation (Phone, Email, etc) Possible values: 'TYPE\_PHONE', 'TYPE\_EMAIL', 'TYPE\_FB\_MESSENGER', 'TYPE\_REVIEW', 'TYPE\_GROUP\_SMS' Example: `TYPE_PHONE`
  - `unreadCount` (number, required): Number of unread messages in this conversation Example: `1`
  - `fullName` (string, required): Complete name of the contact (first and last name) Example: `John Doe`
  - `contactName` (string, required): Alternative display name for the contact - used when full name is not available Example: `John Doe Company`
  - `email` (string, required): Primary email address of the contact Example: `johndoe@mailingdomain.com`
  - `phone` (string, required): Primary phone number of the contact Example: `+15550001234`

- `total` (number, required): Total Number of results found for the given query Example: `100`

```json
{
  "conversations": [
    {
      "id": "ABCHkzuJQ8ZMd4Te84GK",
      "contactId": "ABCHkzuJQ8ZMd4Te84GK",
      "locationId": "ABCHkzuJQ8ZMd4Te84GK",
      "lastMessageBody": "This is a sample message body",
      "lastMessageType": "TYPE_SMS",
      "type": "TYPE_PHONE",
      "unreadCount": 1,
      "fullName": "John Doe",
      "contactName": "John Doe Company",
      "email": "johndoe@mailingdomain.com",
      "phone": "+15550001234"
    }
  ],
  "total": 100
}
```

**400 - Bad Request**

```json
{}
```

**401 - Unauthorized**

```json
{}
```

## Example

```bash cURL
curl -X GET 'https://services.leadconnectorhq.com/conversations/search' \
  -H 'Authorization: Bearer YOUR_TOKEN' \
  -H 'Version: 2021-07-28'
```

```javascript Node.js
const response = await fetch('https://services.leadconnectorhq.com/conversations/search', {
  method: 'GET',
  headers: {
    Authorization: `Bearer ${process.env.LEADWAY_TOKEN}`,
    Version: '2021-07-28',
  },
});
const data = await response.json();
```

```python Python
import os, requests
response = requests.request(
    'GET',
    'https://services.leadconnectorhq.com/conversations/search',
    headers={
        'Authorization': f"Bearer {os.environ['LEADWAY_TOKEN']}",
        'Version': '2021-07-28',
    },
)
data = response.json()
```

```php PHP
<?php
$ch = curl_init('https://services.leadconnectorhq.com/conversations/search');
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST => 'GET',
    CURLOPT_HTTPHEADER => [
        'Authorization: Bearer ' . getenv('LEADWAY_TOKEN'),
        'Version: 2021-07-28',
    ],
]);
$data = json_decode(curl_exec($ch), true);
```
