Get a WABA Conversation Programmatically
Automate this endpoint with an AI agent using the 2chat-whatsapp-waba skill:
npx skills add 2ChatCo/agent-skills -s 2chat-whatsapp-waba
This endpoint returns the conversation between one of your WhatsApp Business API numbers and a single contact, newest first.
It is the one to reach for when you know which contact you care about: it is cheaper than reading the whole number and it reads an indexed path, so paging deep into a long conversation stays fast.
Endpoint
GET https://api.p.2chat.io/open/waba/messages/{from_number}/{to_number}
Authentication
Include your API key in the X-User-API-Key header. Learn more about authentication.
Parameters
| Parameter | In | Required | Description |
|---|---|---|---|
from_number | path | Yes | Your WABA number in E.164 format. The leading + is optional (e.g. +15550001111) |
to_number | path | Yes | The contact's number in E.164 format. The leading + is optional (e.g. +5215512345432) |
page_number | query | No | Zero-based page, paging back in time. Defaults to 0 |
results_per_page | query | No | Messages per page, between 1 and 200. Defaults to 50 |
Paging
page_number is zero-based and results_per_page decides how many messages each one holds, newest first:
- Page 0, the newest:
https://api.p.2chat.io/open/waba/messages/+15550001111/+5215512345432 - Page 1, the 50 before those:
https://api.p.2chat.io/open/waba/messages/+15550001111/+5215512345432?page_number=1 - 200 at a time:
https://api.p.2chat.io/open/waba/messages/+15550001111/+5215512345432?results_per_page=200&page_number=1
has_more, not on a short pageKeep paging while has_more is true.
A contact you have never exchanged messages with is not an error: you get success: true with an empty messages list.
Invocation
- cURL
- Python
- JavaScript
- PHP
curl --location --request GET 'https://api.p.2chat.io/open/waba/messages/+15550001111/+5215512345432?page_number=0' \
--header 'X-User-API-Key: your_api_key_here'
import requests
url = "https://api.p.2chat.io/open/waba/messages/+15550001111/+5215512345432"
headers = {
"X-User-API-Key": "your_api_key_here"
}
response = requests.get(url, params={"page_number": 0, "results_per_page": 50}, headers=headers)
print(response.json())
const axios = require('axios');
const response = await axios.get('https://api.p.2chat.io/open/waba/messages/+15550001111/+5215512345432', {
params: { page_number: 0, results_per_page: 50 },
headers: {
'X-User-API-Key': 'your_api_key_here'
}
});
console.log(response.data);
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.p.2chat.io/open/waba/messages/+15550001111/+5215512345432?page_number=0',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => array(
'X-User-API-Key: your_api_key_here'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
Response
Success (HTTP 200 OK)
{
"success": true,
"page_number": 0,
"results_per_page": 50,
"has_more": false,
"messages": [
{
"id": "MSGaf1fa3a1-0d8d-4aa5-b117-f9425b651485",
"uuid": "MSGaf1fa3a1-0d8d-4aa5-b117-f9425b651485",
"session_key": "WA-WAN95841312-b54d-46e3-b0bc-6414f4a5296b-5215512345432",
"message": {
"text": "hi, do you have this in stock?"
},
"created_at": "2026-09-20T14:03:11",
"remote_phone_number": "+5215512345432",
"channel_phone_number": "+15550001111",
"sent_by": "user"
}
]
}
page_number, results_per_page and has_more behave exactly as in Get Messages by Phone Number, and so do the message fields.
Error
{
"error": true,
"error_message": "WhatsApp Profile setup not found"
}
| HTTP | When |
|---|---|
400 | from_number or to_number is not a valid number in international format, or the page starts past the 50000-message limit |
404 | Your account has no WABA number matching from_number |
422 | page_number is negative, or results_per_page is outside 1–200 |
429 | Too many concurrent reads of the same conversation. Retry shortly |