Skip to main content
GET
/
api
/
conversations
Get Conversations
curl --request GET \
  --url https://api.example.com/api/conversations
{
  "success": true,
  "conversations": [
    {
      "id": 123,
      "phone_number": "<string>",
      "contact_name": "<string>",
      "status": "<string>",
      "ai_enabled": 123,
      "last_message_at": "<string>",
      "created_at": "<string>",
      "last_message": "<string>",
      "last_sender_type": "<string>",
      "last_message_created_at": "<string>"
    }
  ],
  "error": "<string>"
}

Endpoint

GET /api/conversations
Retrieves all conversations from the database with their latest message details. Conversations are ordered by the most recent message timestamp.

Query Parameters

status
string
Filter conversations by status. Valid values:
  • active - Active conversations
  • pending_human - Conversations waiting for human intervention
  • closed - Closed conversations
If omitted, returns all conversations regardless of status.

Response

success
boolean
required
Indicates if the request was successful
conversations
array
required
Array of conversation objects ordered by most recent message
id
integer
Unique conversation identifier
phone_number
string
WhatsApp phone number of the contact
contact_name
string
Name of the contact (if available)
status
string
Current conversation status: active, pending_human, or closed
ai_enabled
integer
Whether AI responses are enabled for this conversation (0 or 1)
last_message_at
string
Timestamp of the last message in ISO 8601 format
created_at
string
Timestamp when the conversation was created
last_message
string
Text content of the most recent message
last_sender_type
string
Who sent the last message: customer, ai, or human
last_message_created_at
string
Timestamp when the last message was sent
error
string
Error message if the request failed (only present when success is false)

Examples

curl -X GET 'https://your-domain.com/api/conversations'

Response Examples

Success Response

{
  "success": true,
  "conversations": [
    {
      "id": 1,
      "phone_number": "1234567890",
      "contact_name": "John Doe",
      "status": "active",
      "ai_enabled": 1,
      "last_message_at": "2024-01-15 14:30:25",
      "created_at": "2024-01-10 09:00:00",
      "last_message": "Thank you for your help!",
      "last_sender_type": "customer",
      "last_message_created_at": "2024-01-15 14:30:25"
    },
    {
      "id": 2,
      "phone_number": "0987654321",
      "contact_name": "Jane Smith",
      "status": "pending_human",
      "ai_enabled": 0,
      "last_message_at": "2024-01-15 13:15:00",
      "created_at": "2024-01-12 11:30:00",
      "last_message": "I need to speak with a human agent",
      "last_sender_type": "customer",
      "last_message_created_at": "2024-01-15 13:15:00"
    }
  ]
}

Error Response

{
  "success": false,
  "error": "Error al obtener conversaciones"
}

Implementation Details

The endpoint is implemented in api/get-conversations.php and uses the ConversationService::getAllConversations() method. The query joins the conversations table with the messages table to fetch the most recent message for each conversation. Route pattern (from index.php:161):
if ($requestMethod === 'GET' && ($path === '/api/conversations' || 
    $path === '/api/get-conversations' || 
    $path === '/api/get-conversations.php'))

Notes

  • Results are limited to 100 conversations by default (configurable in ConversationService.php:77)
  • Conversations are ordered by last_message_at in descending order (most recent first)
  • Returns HTTP 500 status code on error

Build docs developers (and LLMs) love