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

# List Chat Sessions

> List all chat sessions for your account

Retrieve all chat sessions from your chat widgets with pagination support.

## Request Body

<ParamField body="limit" type="integer" default={50}>
  Maximum sessions to return. Max: 100.
</ParamField>

<ParamField body="offset" type="integer" default={0}>
  Number of records to skip for pagination.
</ParamField>

<ParamField body="widget_id" type="string">
  Filter by specific widget UUID.
</ParamField>

<ParamField body="status" type="string">
  Filter by session status: `active` or `closed`.
</ParamField>

<ParamField body="from_date" type="string">
  Filter sessions after this ISO 8601 date.
</ParamField>

## Response

<ResponseField name="sessions" type="array">
  Array of chat session objects with last message preview.
</ResponseField>

<ResponseField name="total" type="integer">
  Total number of sessions matching filters.
</ResponseField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST https://api.magpipe.ai/functions/v1/list-chat-sessions \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{"limit": 20, "status": "active"}'
  ```

  ```javascript Node.js theme={null}
  const response = await fetch(
    'https://api.magpipe.ai/functions/v1/list-chat-sessions',
    {
      method: 'POST',
      headers: {
        'Authorization': 'Bearer YOUR_API_KEY',
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({ limit: 20, status: 'active' }),
    }
  );

  const { sessions, total } = await response.json();
  console.log(`Found ${total} active sessions`);
  ```

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

  response = requests.post(
      'https://api.magpipe.ai/functions/v1/list-chat-sessions',
      headers={
          'Authorization': 'Bearer YOUR_API_KEY',
          'Content-Type': 'application/json',
      },
      json={'limit': 20, 'status': 'active'}
  )

  data = response.json()
  print(f"Found {data['total']} active sessions")
  ```
</RequestExample>

<ResponseExample>
  ```json Success Response theme={null}
  {
    "sessions": [
      {
        "id": "e5f6a7b8-c9d0-1e2f-3a4b-567890cdef12",
        "widget_id": "d4e5f6a7-b8c9-0d1e-2f3a-456789bcdef0",
        "widget_name": "Support Widget",
        "visitor_id": "v_abc123def456",
        "visitor_name": "John",
        "visitor_email": "john@example.com",
        "status": "active",
        "last_message": "Thanks, that helps!",
        "last_message_at": "2024-01-15T10:45:00Z",
        "message_count": 8,
        "page_url": "https://example.com/pricing",
        "created_at": "2024-01-15T10:30:00Z"
      }
    ],
    "total": 24
  }
  ```
</ResponseExample>
