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

# Agent - Export Conversations

> Export conversation history for an agent as a CSV file with filtering options

Export conversation history and message data from an agent in CSV format. Supports filtering by date range, channel, status, and search terms. Use this endpoint to:

* Extract conversation history for analysis or compliance
* Export specific conversations by ID
* Filter messages by channel, status, or date range
* Search for messages by text content

### Path

<ParamField path="id" type="string" required>
  The agent ID to export conversations from
</ParamField>

### Query

#### Optional

<ParamField query="from" type="string">
  Start date in ISO 8601 format (e.g., `2026-01-01T00:00:00Z`)
</ParamField>

<ParamField query="to" type="string">
  End date in ISO 8601 format (e.g., `2026-06-16T23:59:59Z`)
</ParamField>

<ParamField query="conversationId" type="string">
  Comma-separated conversation IDs to export (e.g., `id1,id2,id3`)
</ParamField>

<ParamField query="include" type="enum" default="all">
  Filter by message sender type: `all`, `human`, or `agent`
</ParamField>

<ParamField query="status" type="enum" default="all">
  Filter by conversation status: `all`, `RESOLVED`, `UNRESOLVED`, or `HUMAN_REQUESTED`
</ParamField>

<ParamField query="channel" type="enum" default="all">
  Filter by channel: `all`, `website`, `whatsapp`, `telegram`, `slack`, `dashboard`, `meta`, `mercadolibre`, `chatwoot`, or `crmchatsappai`
</ParamField>

<ParamField query="limit" type="number" default="5000">
  Maximum number of messages to export (1-100000). Default is 5000.
</ParamField>

<ParamField query="preview" type="boolean">
  When `true`, limits results to 100 messages for preview purposes
</ParamField>

<ParamField query="orderBy" type="enum" default="asc">
  Sort messages by creation date: `asc` (ascending) or `desc` (descending)
</ParamField>

<ParamField query="search" type="string">
  Search messages by text content (case-insensitive). Maximum 500 characters.
</ParamField>

### Response

The response is a CSV file with the following columns:

<ResponseField name="conversation_id" type="string">
  Unique identifier of the conversation
</ResponseField>

<ResponseField name="message_from" type="string">
  Sender of the message: `human` or `agent`
</ResponseField>

<ResponseField name="message_text" type="string">
  The message content text
</ResponseField>

<ResponseField name="message_created_at" type="string">
  ISO 8601 timestamp of when the message was created
</ResponseField>

### Error Responses

| Status Code | Type                  | Description                                                                 |
| ----------- | --------------------- | --------------------------------------------------------------------------- |
| 400         | Bad Request           | Invalid query parameters (e.g., invalid date format, search query too long) |
| 401         | UNAUTHORIZED          | Missing or invalid authentication token                                     |
| 404         | NOT\_FOUND            | Agent does not exist or does not belong to your organization                |
| 500         | Internal Server Error | Server error during export processing                                       |

### Notes

<Note>
  The response is a CSV file attachment, not JSON. Set `Accept: text/csv` header to explicitly request CSV format.
</Note>

<Note>
  If no conversations are found, the response will be an empty CSV with headers only: `conversation_id,message_from,message_text,message_created_at`
</Note>

<Warning>
  Special characters in CSV fields are automatically escaped to prevent CSV injection attacks. Text values are quoted and internal quotes are doubled.
</Warning>

<RequestExample>
  ```bash cURL theme={null}
  # Export all conversations for an agent
  curl --location --request GET 'https://dashboard.laburen.com/api/agents/clt7x2a0r0000lb08d9z3f5k1/conversations-export' \
  --header 'Authorization: Bearer <API_KEY>'
  ```

  ```bash cURL with Filters theme={null}
  # Export conversations from specific date range and channel
  curl --location --request GET 'https://dashboard.laburen.com/api/agents/clt7x2a0r0000lb08d9z3f5k1/conversations-export?from=2026-01-01T00:00:00Z&to=2026-06-16T23:59:59Z&channel=whatsapp&status=RESOLVED' \
  --header 'Authorization: Bearer <API_KEY>'
  ```

  ```javascript JavaScript theme={null}
  const apiUrl = 'https://dashboard.laburen.com/api';
  const apiKey = '<API_KEY>';
  const agentId = 'clt7x2a0r0000lb08d9z3f5k1';

  const response = await fetch(`${apiUrl}/agents/${agentId}/conversations-export?from=2026-01-01T00:00:00Z&to=2026-06-16T23:59:59Z`, {
    method: 'GET',
    headers: {
      'Authorization': `Bearer ${apiKey}`,
    },
  });

  const csv = await response.text();
  console.log(csv);
  ```

  ```python Python theme={null}
  import requests

  api_url = "https://dashboard.laburen.com/api"
  api_key = "<API_KEY>"
  agent_id = "clt7x2a0r0000lb08d9z3f5k1"

  response = requests.get(
      f"{api_url}/agents/{agent_id}/conversations-export",
      headers={
          "Authorization": f"Bearer {api_key}",
      },
      params={
          "from": "2026-01-01T00:00:00Z",
          "to": "2026-06-16T23:59:59Z",
          "channel": "whatsapp",
      }
  )

  csv_data = response.text
  print(csv_data)
  ```
</RequestExample>

<ResponseExample>
  ```csv Response theme={null}
  conversation_id,message_from,message_text,message_created_at
  "conv_123abc","human","Hola, necesito ayuda","2026-06-16T10:30:00.000Z"
  "conv_123abc","agent","Claro, ¿en qué puedo ayudarte?","2026-06-16T10:31:00.000Z"
  "conv_123abc","human","Tengo una pregunta sobre mi pedido","2026-06-16T10:32:00.000Z"
  "conv_456def","human","Hola","2026-06-16T15:00:00.000Z"
  "conv_456def","agent","Bienvenido, ¿cómo estás?","2026-06-16T15:01:00.000Z"
  ```
</ResponseExample>
