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

# Get workspace messages

> Retrieve message history for a workspace with pagination and filtering

## Authentication

This endpoint requires user authentication. You must be a member of the workspace to access its messages.

## Path Parameters

<ParamField path="workspaceId" type="string" required>
  The unique identifier of the workspace
</ParamField>

## Query Parameters

<ParamField query="page" type="number">
  The page number for pagination (default: 1)
</ParamField>

<ParamField query="limit" type="number">
  The number of messages per page (default: 50, max: 100)
</ParamField>

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

<ParamField query="status" type="string">
  Filter by message status: "queued", "sent", "delivered", "failed", etc.
</ParamField>

<ParamField query="from" type="string">
  Filter by sender phone number
</ParamField>

<ParamField query="to" type="string">
  Filter by recipient phone number
</ParamField>

<ParamField query="startDate" type="string">
  Filter messages after this date (ISO 8601 format)
</ParamField>

<ParamField query="endDate" type="string">
  Filter messages before this date (ISO 8601 format)
</ParamField>

## Response

<ResponseField name="messages" type="array">
  Array of message objects
</ResponseField>

<ResponseField name="messages[].id" type="string">
  Unique identifier of the message
</ResponseField>

<ResponseField name="messages[].direction" type="string">
  Direction of the message: "inbound" or "outbound"
</ResponseField>

<ResponseField name="messages[].to" type="string">
  Recipient phone number
</ResponseField>

<ResponseField name="messages[].from" type="string">
  Sender phone number
</ResponseField>

<ResponseField name="messages[].body" type="string">
  Content of the message
</ResponseField>

<ResponseField name="messages[].status" type="string">
  Current status of the message
</ResponseField>

<ResponseField name="messages[].provider_sid" type="string">
  Provider's unique identifier for the message
</ResponseField>

<ResponseField name="messages[].created_at" type="string">
  Timestamp when the message was created
</ResponseField>

<ResponseField name="pagination" type="object">
  Pagination information
</ResponseField>

<ResponseField name="pagination.currentPage" type="number">
  Current page number
</ResponseField>

<ResponseField name="pagination.totalPages" type="number">
  Total number of pages
</ResponseField>

<ResponseField name="pagination.totalMessages" type="number">
  Total number of messages
</ResponseField>

<ResponseField name="pagination.hasNext" type="boolean">
  Whether there are more pages
</ResponseField>

<ResponseExample>
  ```json theme={null}
  {
    "messages": [
      {
        "id": "msg_abc123",
        "direction": "outbound",
        "to": "+15551234567",
        "from": "+15559876543",
        "body": "Hello, this is a test message",
        "status": "delivered",
        "provider_sid": "SMxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
        "created_at": "2024-01-15T10:30:00Z"
      }
    ],
    "pagination": {
      "currentPage": 1,
      "totalPages": 5,
      "totalMessages": 234,
      "hasNext": true
    }
  }
  ```
</ResponseExample>

<RequestExample>
  ```bash theme={null}
  curl "https://api.example.com/api/ui/workspaces/workspace_123/messages?page=1&limit=50&direction=outbound" \
    -H "Authorization: Bearer YOUR_SESSION_TOKEN"
  ```

  ```javascript theme={null}
  const response = await fetch('https://api.example.com/api/ui/workspaces/workspace_123/messages?page=1&limit=50', {
    headers: {
      'Authorization': 'Bearer YOUR_SESSION_TOKEN'
    }
  });

  const data = await response.json();
  ```

  ```python theme={null}
  import requests

  response = requests.get(
      'https://api.example.com/api/ui/workspaces/workspace_123/messages',
      headers={
          'Authorization': 'Bearer YOUR_SESSION_TOKEN'
      },
      params={
          'page': 1,
          'limit': 50,
          'direction': 'outbound'
      }
  )

  data = response.json()
  ```
</RequestExample>
