Overview
Retrieve messages from a contact with pagination support. This endpoint returns a flat list of messages in chronological order, perfect for processing large message histories efficiently. This is the recommended endpoint for accessing message history when you need pagination, sequential processing, or want to handle large datasets.Use Cases
- Message Processing: Process messages sequentially for analytics or exports
- Large Message Histories: Handle contacts with thousands of messages efficiently
- Data Export: Export all messages in chunks
- Message Analytics: Analyze message patterns, response times, sentiment
- Search & Filter: Build custom message search and filtering
- Audit Logs: Create audit trails of all communications
Authentication
This endpoint requires authentication using an API key. Include your API key in the request header:Path Parameters
Parameter | Type | Required | Description |
---|---|---|---|
aiContactId | string (UUID) | Yes | Unique identifier of the contact |
Query Parameters
Parameter | Type | Required | Description |
---|---|---|---|
page | number | Yes | Page number to retrieve (starts at 1) |
Pagination: Each page returns a fixed number of messages. Keep
incrementing
page
until you receive an empty array.Response Structure
Returns an object with pagination information and messages:Field | Type | Description |
---|---|---|
messages | array | Array of message objects for this page |
page | number | Current page number |
hasMore | boolean | Whether there are more pages available |
total | number | Total number of messages (optional) |
Message Object
Field | Type | Description |
---|---|---|
id | string (UUID) | Unique message identifier |
body | string | Message content/text |
created_at | string (ISO) | Message timestamp |
direction | string | ”INBOUND” or “OUTBOUND” |
from | string | Sender identifier (phone/username) |
to | string | Recipient identifier |
type | string | Message type (text, image, video, audio, etc.) |
status | string | Delivery status (sent, delivered, read, failed) |
media_url | string | null | URL to media file (if applicable) |
client_id | string (UUID) | Your organization ID |
ai_contact_id | string (UUID) | Associated contact ID |
Example Requests
Get First Page
Get Second Page
Example Response
Common Use Cases
1. Fetch All Messages with Pagination
2. Export Messages to CSV
3. Calculate Response Time Metrics
4. Find Messages with Specific Content
5. Get Latest Messages Only
Pagination Details
Page Size
- Each page typically returns 20-50 messages (exact number may vary)
- Pages are numbered starting from 1
- Messages are ordered chronologically (oldest to newest or newest to oldest)
Fetching All Pages
Error Responses
Status Code | Description |
---|---|
400 | Bad Request - Invalid page parameter |
401 | Unauthorized - Invalid or missing API key |
404 | Not Found - Contact not found |
500 | Internal Server Error - Something went wrong |
Important Notes
- Pagination Required: The
page
parameter is mandatory - Page Starts at 1: First page is 1, not 0
- No Total Count: Response may not include total message count
- Check hasMore: Use
hasMore
field to determine if more pages exist - Cross-Channel: Works with all communication channels
- Include Stage History: Messages include stage change events
When to Use This vs Conversations
Requirement | Use This Endpoint (Messages v2) | Use Conversations |
---|---|---|
Need pagination | ✅ Yes | ❌ No |
Large message history | ✅ Yes | ❌ No |
Flat message list | ✅ Yes | ❌ No |
Sequential processing | ✅ Yes | ❌ No |
Chat UI with threads | ❌ No | ✅ Yes |
Conversation view | ❌ No | ✅ Yes |
Human-readable format | ❌ No | ✅ Yes |
Filter by recent days | Use pagination | ✅ daysBack parameter |
Related Endpoints
- GET /api/public/contact//conversations - Get conversations grouped (better for chat UI)
- GET /api/public/contact//info - Get contact info
- GET /api/public/contacts/search - Search contacts by phone/email
Best Practices
1. Handle Empty Pages
2. Implement Rate Limiting
3. Cache Pages
Headers
API key required to authorize the request
Path Parameters
ID of the AI contact
Query Parameters
Page number
Response
Messages retrieved successfully.