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

> List SMS messages with filtering and pagination

Retrieve a paginated list of messages for your account. Supports filtering by direction, phone number, and date range.

## Request Body

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

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

<ParamField body="direction" type="string">
  Filter by message direction: `inbound` or `outbound`.
</ParamField>

<ParamField body="phone_number" type="string">
  Filter by phone number (either from or to).
</ParamField>

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

<ParamField body="to_date" type="string">
  Filter messages before this ISO 8601 date.
</ParamField>

## Response

<ResponseField name="messages" type="array">
  Array of message objects. Each carries a `thread_id` (stable conversation id — same for every message between a contact and service number), a `media` array (attachments with 24h-signed `url`, `mime_type`, `kind`, `caption`; empty when none), and a `delivery_error` object (`code`, `reason`, `at`) when `status` is `failed` or `undelivered`, otherwise `null`. See [Get Message](/api-reference/endpoints/get-message) for the full per-message shape.
</ResponseField>

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

<ResponseField name="has_more" type="boolean">
  Whether there are more messages to paginate through.
</ResponseField>

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

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

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

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

  response = requests.post(
      'https://api.magpipe.ai/functions/v1/list-messages',
      headers={
          'Authorization': 'Bearer YOUR_API_KEY',
          'Content-Type': 'application/json',
      },
      json={
          'limit': 20,
          'phone_number': '+14155551234'
      }
  )

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

<ResponseExample>
  ```json Success Response theme={null}
  {
    "messages": [
      {
        "id": "8e4f9a00-c3d4-6e5f-1a2b-890123cdef01",
        "thread_id": "a17b4735-15d2-5274-9460-74f8554172cb",
        "from_number": "+16045551234",
        "to_number": "+14155551234",
        "body": "Your appointment is confirmed for tomorrow at 2pm.",
        "direction": "outbound",
        "status": "delivered",
        "is_ai_generated": false,
        "created_at": "2024-01-15T10:30:00Z",
        "media": [],
        "delivery_error": null
      },
      {
        "id": "7d3e8b00-b2c3-5d4e-0a1b-789012bcde01",
        "thread_id": "a17b4735-15d2-5274-9460-74f8554172cb",
        "from_number": "+14155551234",
        "to_number": "+16045551234",
        "body": "Thank you! I'll be there.",
        "direction": "inbound",
        "status": "delivered",
        "is_ai_generated": false,
        "created_at": "2024-01-15T10:35:00Z",
        "media": [],
        "delivery_error": null
      },
      {
        "id": "6c2d7a00-a1b2-4c3d-9f0a-678901abcd01",
        "thread_id": "f0e1d2c3-b4a5-5968-8776-554433221100",
        "from_number": "+16045551234",
        "to_number": "+14155550000",
        "body": "Reminder: your invoice is due.",
        "direction": "outbound",
        "status": "undelivered",
        "is_ai_generated": false,
        "created_at": "2024-01-15T10:40:00Z",
        "media": [],
        "delivery_error": {
          "code": "30003",
          "reason": "Unreachable destination handset",
          "at": "2024-01-15T10:40:05Z"
        }
      }
    ],
    "total": 42,
    "has_more": true
  }
  ```
</ResponseExample>
