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

# Export messages by account ID

> Export messages for a specific account with cursor-based pagination support. Response includes messageType (string), source, and subType fields. The channel parameter is optional - if not provided, al

Export messages for a specific account with cursor-based pagination support. Response includes messageType (string), source, and subType fields. The channel parameter is optional - if not provided, all non-email message types will be returned including activity messages (opportunity updates, appointments, etc.).

```http theme={null}
GET https://services.leadconnectorhq.com/conversations/messages/export
```

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

## Query parameters

<ParamField query="locationId" type="string" required>
  Account ID to filter messages by
</ParamField>

<ParamField query="limit" type="number">
  Number of messages to return per page
</ParamField>

<ParamField query="cursor" type="string" default="eyJwaXRJZCI6ImFiYy0xMjMiLCJsYXN0U29ydCI6WzE2NDY4NjQ0MDBdLCJsYXN0SWQiOiIxMjMifQ==">
  Cursor for pagination. Pass the nextCursor from previous response to get next page.
</ParamField>

<ParamField query="sortBy" type="string">
  Field to sort by
</ParamField>

<ParamField query="sortOrder" type="string">
  Sort order
</ParamField>

<ParamField query="conversationId" type="string">
  Filter messages by conversation ID
</ParamField>

<ParamField query="contactId" type="string">
  Filter messages by contact ID
</ParamField>

<ParamField query="channel" type="string">
  Filter by message channel. If not provided, all non-email message types will be returned including activity messages (opportunity updates, appointments, etc.)
</ParamField>

<ParamField query="startDate" type="string">
  Start date to filter messages by
</ParamField>

<ParamField query="endDate" type="string">
  End date to filter messages by
</ParamField>

## Respuestas

<Accordion title="200 - List of messages for the account with pagination details.">
  <ResponseField name="messages" type="object[]" required>
    Array of messages

    <Expandable title="cada item">
      <ResponseField name="id" type="string" required default="ve9EPM428h8vShlRW1KT" />

      <ResponseField name="type" type="number" required default="1" />

      <ResponseField name="messageType" type="string" required default="SMS">
        Type of the message as a string Posibles valores: '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'
      </ResponseField>

      <ResponseField name="locationId" type="string" required default="ve9EPM428h8vShlRW1KT" />

      <ResponseField name="contactId" type="string" required default="ve9EPM428h8vShlRW1KT" />

      <ResponseField name="conversationId" type="string" required default="ve9EPM428h8vShlRW1KT" />

      <ResponseField name="dateAdded" type="string" required default="2024-03-27T18:13:49.000Z" />

      <ResponseField name="body" type="string" default="Hi there" />

      <ResponseField name="direction" type="string" required>
        Posibles valores: 'inbound', 'outbound'
      </ResponseField>

      <ResponseField name="status" type="string">
        Posibles valores: 'connected', 'delivered', 'failed', 'opened', 'pending', 'read', 'scheduled', 'sent', 'undelivered', 'clicked', 'opt\_out', 'queued'
      </ResponseField>

      <ResponseField name="contentType" type="string" required default="text/plain" />

      <ResponseField name="attachments" type="string[]">
        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.
      </ResponseField>

      <ResponseField name="meta" type="object">
        <Expandable title="propiedades">
          <ResponseField name="callDuration" type="string" default="120">
            Call duration in seconds
          </ResponseField>

          <ResponseField name="callStatus" type="string" default="completed">
            Call status - can be pending, completed, answered, busy, no-answer, failed, canceled, or voicemail Posibles valores: 'pending', 'completed', 'answered', 'busy', 'no-answer', 'failed', 'canceled', 'voicemail'
          </ResponseField>

          <ResponseField name="email" type="object">
            meta will contain email, for message type 3 (email). messageIds is list of all email message ids under the message thread
          </ResponseField>
        </Expandable>
      </ResponseField>

      <ResponseField name="source" type="string">
        Message source Posibles valores: 'workflow', 'bulk\_actions', 'campaign', 'api', 'app'
      </ResponseField>

      <ResponseField name="userId" type="string" default="ve9EPM428kjkvShlRW1KT">
        User Id
      </ResponseField>

      <ResponseField name="conversationProviderId" type="string" default="ve9EPM428kjkvShlRW1KT">
        Conversation Provider Id
      </ResponseField>

      <ResponseField name="chatWidgetId" type="string" default="67b0cc8cf14b19d85ace7s35">
        Chat Widget Id
      </ResponseField>
    </Expandable>
  </ResponseField>

  <ResponseField name="nextCursor" type="string" default="eyJwaXRJZCI6ImFiYy0xMjMiLCJsYXN0U29ydCI6WzE2NDY4NjQ0MDBdLCJsYXN0SWQiOiIxMjMifQ==">
    Cursor for fetching next page. Null if no more results.
  </ResponseField>

  <ResponseField name="total" type="number" required default="1234">
    Total number of messages matching the query
  </ResponseField>

  ```json theme={null}
  {
    "messages": [
      {
        "id": "ve9EPM428h8vShlRW1KT",
        "type": 1,
        "messageType": "SMS",
        "locationId": "ve9EPM428h8vShlRW1KT",
        "contactId": "ve9EPM428h8vShlRW1KT",
        "conversationId": "ve9EPM428h8vShlRW1KT",
        "dateAdded": "2024-03-27T18:13:49.000Z",
        "body": "Hi there",
        "direction": "inbound",
        "status": "connected",
        "contentType": "text/plain",
        "attachments": [
          "string"
        ],
        "meta": {
          "callDuration": 120,
          "callStatus": "completed",
          "email": {
            "email": {
              "messageIds": [
                "ve9EPM428kjkvShlRW1KT",
                "ve9EPs1028kjkvShlRW1KT"
              ]
            }
          }
        },
        "source": "workflow",
        "userId": "ve9EPM428kjkvShlRW1KT",
        "conversationProviderId": "ve9EPM428kjkvShlRW1KT",
        "chatWidgetId": "67b0cc8cf14b19d85ace7s35"
      }
    ],
    "nextCursor": "eyJwaXRJZCI6ImFiYy0xMjMiLCJsYXN0U29ydCI6WzE2NDY4NjQ0MDBdLCJsYXN0SWQiOiIxMjMifQ==",
    "total": 1234
  }
  ```
</Accordion>

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

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

## Ejemplo

<CodeGroup>
  ```bash cURL theme={null}
  curl -X GET 'https://services.leadconnectorhq.com/conversations/messages/export' \
    -H 'Authorization: Bearer YOUR_TOKEN' \
    -H 'Version: 2021-07-28'
  ```

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

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

  ```php PHP theme={null}
  <?php
  $ch = curl_init('https://services.leadconnectorhq.com/conversations/messages/export');
  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);
  ```
</CodeGroup>
