# Get messages by conversation id

GET https://services.leadconnectorhq.com/conversations/{conversationId}/messages

Get messages by conversation id.

## Authentication

Send `Authorization: Bearer <token>` using:

- **Sub-Account token: OAuth access token or Private Integration Token.** Scopes: `conversations/message.readonly`

## Parameters

### Header Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `Version` | string | Yes | API Version |

### Path Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `conversationId` | string | Yes | Conversation ID as string |

### Query Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `lastMessageId` | string | No | Message ID of the last message in the list as a string |
| `limit` | number | No | Number of messages to be fetched from the conversation. Default limit is 20 |
| `type` | string | No | Types of message to fetched separated with comma |

## OpenAPI Specification

```json
{
  "openapi": "3.0.0",
  "info": {
    "title": "LeadConnector API",
    "version": "v3"
  },
  "servers": [
    {
      "url": "https://services.leadconnectorhq.com"
    }
  ],
  "paths": {
    "/conversations/{conversationId}/messages": {
      "get": {
        "summary": "Get messages by conversation id",
        "operationId": "getMessagesByConversationId",
        "description": "Get messages by conversation id.",
        "parameters": [
          {
            "name": "Version",
            "in": "header",
            "description": "API Version",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "v3"
              ]
            }
          },
          {
            "name": "conversationId",
            "required": true,
            "in": "path",
            "description": "Conversation ID as string",
            "schema": {
              "example": "tDtDnQdgm2LXpyiqYvZ6",
              "type": "string"
            }
          },
          {
            "name": "lastMessageId",
            "required": false,
            "in": "query",
            "description": "Message ID of the last message in the list as a string",
            "schema": {
              "example": "tDtDnQdgm2LXpyiqYvZ6",
              "type": "string"
            }
          },
          {
            "name": "limit",
            "required": false,
            "in": "query",
            "description": "Number of messages to be fetched from the conversation. Default limit is 20",
            "schema": {
              "example": 20,
              "type": "number"
            }
          },
          {
            "name": "type",
            "required": false,
            "in": "query",
            "description": "Types of message to fetched separated with comma",
            "schema": {
              "example": "TYPE_SMS,TYPE_CALL",
              "enum": [
                "TYPE_CALL",
                "TYPE_SMS",
                "TYPE_EMAIL",
                "TYPE_FACEBOOK",
                "TYPE_GMB",
                "TYPE_INSTAGRAM",
                "TYPE_WHATSAPP",
                "TYPE_ACTIVITY_APPOINTMENT",
                "TYPE_ACTIVITY_CONTACT",
                "TYPE_ACTIVITY_INVOICE",
                "TYPE_ACTIVITY_PAYMENT",
                "TYPE_ACTIVITY_OPPORTUNITY",
                "TYPE_LIVE_CHAT",
                "TYPE_INTERNAL_COMMENTS",
                "TYPE_ACTIVITY_EMPLOYEE_ACTION_LOG"
              ],
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "List of messages for the conversation id of the given type.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GetMessagesByConversationResponseDto"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BadRequestDTO"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UnauthorizedDTO"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearer": [
              "conversations/message.readonly"
            ]
          }
        ]
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearer": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Sub-Account (OR) Private Integration Token of Sub-Account.",
        "type": "http"
      },
      "Location-Access": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Sub-Account (OR) Private Integration Token of Sub-Account.",
        "type": "http"
      },
      "Location-Access-Only": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Sub-Account.",
        "type": "http"
      },
      "Agency-Access": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Agency (OR) Private Integration Token of Agency.",
        "type": "http"
      }
    },
    "schemas": {
      "GetMessagesByConversationResponseDto": {
        "type": "object",
        "properties": {
          "messages": {
            "type": "object",
            "properties": {
              "lastMessageId": {
                "type": "string",
                "description": "Id of the last message in the messages array",
                "example": "p1mRSHeLDhAms5q0LMr4"
              },
              "nextPage": {
                "type": "boolean",
                "description": "Next page value true indicates only 20 message is in the response. Rest of the messages are in the next page. Please use the lastMessageId value in the query to get the next page messages",
                "example": true
              },
              "messages": {
                "description": "Array of messages",
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "example": "ve9EPM428h8vShlRW1KT"
                    },
                    "altId": {
                      "type": "string",
                      "description": "Alternative identifier for the message",
                      "example": "msg_123456789"
                    },
                    "type": {
                      "type": "number",
                      "example": 1
                    },
                    "messageType": {
                      "type": "string",
                      "description": "Type of the message as a string",
                      "example": "SMS",
                      "enum": [
                        "TYPE_CALL",
                        "TYPE_SMS",
                        "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"
                      ]
                    },
                    "locationId": {
                      "type": "string",
                      "example": "ve9EPM428h8vShlRW1KT"
                    },
                    "contactId": {
                      "type": "string",
                      "example": "ve9EPM428h8vShlRW1KT"
                    },
                    "conversationId": {
                      "type": "string",
                      "example": "ve9EPM428h8vShlRW1KT"
                    },
                    "dateAdded": {
                      "type": "string",
                      "example": "2024-03-27T18:13:49.000Z"
                    },
                    "body": {
                      "type": "string",
                      "example": "Hi there"
                    },
                    "direction": {
                      "type": "string",
                      "enum": [
                        "inbound",
                        "outbound"
                      ]
                    },
                    "status": {
                      "type": "string",
                      "enum": [
                        "connected",
                        "delivered",
                        "failed",
                        "opened",
                        "pending",
                        "read",
                        "scheduled",
                        "sent",
                        "undelivered",
                        "clicked",
                        "opt_out"
                      ]
                    },
                    "contentType": {
                      "type": "string",
                      "example": "text/plain"
                    },
                    "attachments": {
                      "description": "An array of attachment URLs. Attachments will be empty for Call and Voicemails, type 1 and 10. Please use get call recording API to fetch call recording and voicemails.",
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "callDuration": {
                          "type": "string",
                          "description": "Call duration in seconds",
                          "example": 120
                        },
                        "callStatus": {
                          "type": "string",
                          "description": "Call status - can be pending, completed, answered, busy, no-answer, failed, canceled, or voicemail",
                          "example": "completed",
                          "enum": [
                            "pending",
                            "completed",
                            "answered",
                            "busy",
                            "no-answer",
                            "failed",
                            "canceled",
                            "voicemail"
                          ]
                        },
                        "email": {
                          "type": "object",
                          "description": "meta will contain email, for message type 3 (email). messageIds is list of all email message ids under the message thread",
                          "example": {
                            "email": {
                              "messageIds": [
                                "ve9EPM428kjkvShlRW1KT",
                                "ve9EPs1028kjkvShlRW1KT"
                              ]
                            }
                          }
                        },
                        "ig": {
                          "type": "object",
                          "description": "meta will contain ig, for message type 18 (instagram).",
                          "example": {
                            "ig": {
                              "page_id": "1234567890",
                              "page_name": "Instagram Page"
                            }
                          }
                        },
                        "fb": {
                          "type": "object",
                          "description": "meta will contain fb, for message type 11 (facebook).",
                          "example": {
                            "fb": {
                              "page_id": "1234567890",
                              "page_name": "Facebook Page"
                            }
                          }
                        }
                      },
                      "title": "MessageMeta"
                    },
                    "source": {
                      "type": "string",
                      "enum": [
                        "workflow",
                        "bulk_actions",
                        "campaign",
                        "api",
                        "app"
                      ],
                      "description": "Message source"
                    },
                    "userId": {
                      "type": "string",
                      "description": "User Id",
                      "example": "ve9EPM428kjkvShlRW1KT"
                    },
                    "conversationProviderId": {
                      "type": "string",
                      "description": "Conversation Provider Id",
                      "example": "ve9EPM428kjkvShlRW1KT"
                    },
                    "chatWidgetId": {
                      "type": "string",
                      "description": "Chat Widget Id",
                      "example": "67b0cc8cf14b19d85ace7s35"
                    },
                    "from": {
                      "type": "string",
                      "description": "Sender identifier (phone/name). Not returned for email types.",
                      "example": "+14155551234"
                    },
                    "to": {
                      "type": "string",
                      "description": "Recipient identifier (phone/name). Not returned for email types.",
                      "example": "+14155555678"
                    },
                    "error": {
                      "type": "string",
                      "description": "Error message if message delivery failed"
                    }
                  },
                  "required": [
                    "id",
                    "type",
                    "messageType",
                    "locationId",
                    "contactId",
                    "conversationId",
                    "dateAdded",
                    "direction",
                    "contentType"
                  ],
                  "title": "GetMessageResponseDto"
                }
              }
            },
            "required": [
              "lastMessageId",
              "nextPage",
              "messages"
            ]
          }
        },
        "required": [
          "messages"
        ],
        "title": "GetMessagesByConversationResponseDto"
      },
      "BadRequestDTO": {
        "type": "object",
        "properties": {
          "statusCode": {
            "type": "number",
            "example": 400
          },
          "message": {
            "type": "string",
            "example": "Bad Request"
          }
        },
        "title": "BadRequestDTO"
      },
      "UnauthorizedDTO": {
        "type": "object",
        "properties": {
          "statusCode": {
            "type": "number",
            "example": 401
          },
          "message": {
            "type": "string",
            "example": "Invalid token: access token is invalid"
          },
          "error": {
            "type": "string",
            "example": "Unauthorized"
          }
        },
        "title": "UnauthorizedDTO"
      }
    }
  }
}
```

## Code Examples

**cURL**

```bash
curl -L -X GET 'https://services.leadconnectorhq.com/conversations/<conversationId>/messages' \
  -H 'Authorization: Bearer <TOKEN>' \
  -H 'Version: v3'
```

**Node.js**

```javascript
const options = {
  method: 'GET',
  headers: {
    Authorization: 'Bearer <TOKEN>',
    Version: 'v3'
  }
};

try {
  const response = await fetch('https://services.leadconnectorhq.com/conversations/<conversationId>/messages', options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

**Python**

```python
import requests

url = "https://services.leadconnectorhq.com/conversations/{conversationId}/messages"

headers = {
    "Authorization": "Bearer <TOKEN>",
    "Version": "v3"
}

response = requests.get(url, headers=headers)
print(response.json())
```

**PHP**

```php
<?php
$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => 'https://services.leadconnectorhq.com/conversations/<conversationId>/messages',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_CUSTOMREQUEST => 'GET',
  CURLOPT_HTTPHEADER => [
    'Authorization: Bearer <TOKEN>',
    'Version: v3',
  ],
]);

$response = curl_exec($curl);
curl_close($curl);
echo $response;
```

**Java**

```java
HttpResponse<String> response = Unirest
  .get("https://services.leadconnectorhq.com/conversations/<conversationId>/messages")
  .header("Authorization", "Bearer <TOKEN>")
  .header("Version", "v3")
  .asString();
```

**Go**

```go
package main

import (
  "fmt"
  "net/http"
  "io"
)

func main() {
  url := "https://services.leadconnectorhq.com/conversations/<conversationId>/messages"
  req, _ := http.NewRequest("GET", url, nil)
  req.Header.Add("Authorization", "Bearer <TOKEN>")
  req.Header.Add("Version", "v3")

  res, _ := http.DefaultClient.Do(req)
  defer res.Body.Close()
  body, _ := io.ReadAll(res.Body)
  fmt.Println(string(body))
}
```

**Ruby**

```ruby
require 'uri'
require 'net/http'

url = URI("https://services.leadconnectorhq.com/conversations/<conversationId>/messages")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Get.new(url)
request["Authorization"] = "Bearer <TOKEN>"
request["Version"] = "v3"

response = http.request(request)
puts response.read_body
```

**PowerShell**

```powershell
$headers = @{
  "Authorization" = "Bearer <TOKEN>"
  "Version" = "v3"
}

$response = Invoke-RestMethod -Uri 'https://services.leadconnectorhq.com/conversations/<conversationId>/messages' -Method 'GET' -Headers $headers
$response | ConvertTo-Json
```
