Get WhatsApp Message History API
Description
Retrieve message history for a WhatsApp session, including all sent and received messages.
You can fetch the full history of a session or a specific chat with a contact.
Endpoints
1️⃣ Get All Message History (All Chats)
GET https://api.walytic.com/api/whatsapp/:sessionId/history
Fetches all message history (both incoming and outgoing) for the given WhatsApp session.
2️⃣ Get Chat History (Specific Number)
GET https://api.walytic.com/api/whatsapp/:sessionId/history/:number
Fetches all messages exchanged between the WhatsApp session and a specific phone number.
Required Headers
Header |
Type |
Description |
x-api-key |
String |
Your API Key for authentication |
Authorization |
Bearer Token |
(Optional) JWT token for dashboard access |
Path Parameters
Parameter |
Type |
Description |
sessionId |
String |
The WhatsApp session ID |
number |
String |
(Optional) Target contact’s number with country code (e.g., 919876555510) |
Example Node.js Integration
Fetch All Message History
const axios = require("axios");
async function getAllHistory() {
try {
const response = await axios.get(
"https://api.walytic.com/api/whatsapp/919875555210/history",
{
headers: { "x-api-key": "YOUR_API_KEY" }
}
);
console.log("✅ All Message History:");
console.log(response.data);
} catch (error) {
console.error("❌ Error fetching history:", error.response?.data || error.message);
}
}
getAllHistory();
Fetch Chat History for a Specific Number
const axios = require("axios");
async function getChatHistory() {
try {
const response = await axios.get(
"https://api.walytic.com/api/whatsapp/919333343210/history/919812345678",
{
headers: { "x-api-key": "YOUR_API_KEY" }
}
);
console.log("✅ Chat History with Contact:");
console.log(response.data);
} catch (error) {
console.error("❌ Error fetching specific chat:", error.response?.data || error.message);
}
}
getChatHistory();
Example Success Response
{
"success": true,
"data": [
{
"_id": "66f9f2e1d31e2b11a63e1c02",
"sender": "919876543210",
"recipient": "919812345678@s.whatsapp.net",
"content": "Hello!",
"direction": "out",
"status": "sent",
"createdAt": "2025-10-09T10:45:00Z"
},
{
"_id": "66f9f2e1d31e2b11a63e1c01",
"sender": "919812345678@s.whatsapp.net",
"recipient": "919876543210",
"content": "Hi there!",
"direction": "in",
"status": "delivered",
"createdAt": "2025-10-09T10:40:00Z"
}
]
}
Example Error Response
{
"success": false,
"error": "Failed to fetch history"
}