Get messages in chat

Retrieve messages from a specific chat with filtering and pagination.

GET
https://api.wawp.net/v2/chats/messages?access_token=YOUR_ACCESS_TOKEN&chatId=201234567890%40c.us&downloadMedia=true&instance_id=123456789&limit=50&offset=0

Authentication Required

Login to swap the placeholders with your real Instance ID and Access Token.

Log In
Test /v2/chats/messages endpoint
GET
GET

No query parameters required

This endpoint doesn't expect data in the URL.

Fetch Chat History

Retrieve previous messages to build a complete conversation view in your application.

Deep Context: Mastering Message Retrieval and Media Hydration

The /v2/chats/messages endpoint is the technical core of any WhatsApp-based CRM or Support Dashboard. It allows your application to "look back in time," reconstructing the conversational flow with precision. This endpoint handles everything from simple text history to complex media acquisition, making it a powerful but resource-intensive tool that requires a thoughtful implementation strategy.


🏗️ Technical Architecture of Retrieval

When you query for messages, the Wawp engine performs several operations:

  1. JID Resolution: It verifies the chatId and identifies the local storage partition for that specific conversation.
  2. Pointer Management: Using limit and offset, tips: [ { "type": "info", "title": "Rate Limits", "content": "Be mindful of API rate limits to act responsibly." }, { "type": "warning", "title": "Error Handling", "content": "Always handle potential API errors." } ], recommendations: [ "Consult the official documentation for detailed parameter descriptions.", "Test endpoints in a sandbox environment before production.", "Keep your API client library up to date." ],

it navigates the indexed message store to retrieve a deterministic slice of history. 3. Media "Lazy Loading": If downloadMedia is enabled, the engine actively attempts to fetch regional binary data from WhatsApp's CDN, decrypt it using the session's keys, and return it as a Base64 payload.


🚀 Optimized History Synchronization Strategies

For developers building a local message archive, we recommend the Recursive Backfill pattern:

1. The "Infinite Scroll" Implementation

In your UI, when a user scrolls to the top of the chat:

  • Trigger: Detact the scroll event and call /v2/chats/messages with the next offset.
  • Loading State: Show a subtle spinner. Once the messages arrive, prepend them to your local array.
  • Deduplication: Always check for duplicate messageId strings before updating your UI to avoid "Ghost Messages" during fast scrolling.

2. Strategic Media Handling (The "Pay-As-You-Go" Model)

Downloading media for every message in a history fetch is inefficient and can cause significant network lag.

  • The Best Practice: Always set downloadMedia: false when retrieving lists.
  • Hydration on Demand: Your UI should show a placeholder icon (e.g., a "Download" button) for media messages. Only when the user clicks that specific message should you call /v2/message/get with downloadMedia: true.

🛡️ Best Practices for Data Integrity

  • Message Types: WhatsApp has dozens of message types (text, image, video, document, link-preview, location, contact). Ensure your frontend "Message Component" is flexible enough to render these different structures based on the type field in the response.
  • Timestamp Synchronization: Wawp returns timestamps in Unix Epoch format. Always convert these to the user's local timezone on the client-side to ensure conversational context.
  • The "Forwarded" Flag: Pay attention to the isForwarded metadata. In security-sensitive applications, this helps agents identify if a customer is sharing original content or potentially circulating spam/template information.

🧩 Advanced Use Cases

Conversational AI Memory (RAG)

If you are building an AI bot using RAG (Retrieval-Augmented Generation), use this endpoint to provide the LLM with the last 20 messages of context.

  • Logic: Fetch the messages without media, concatenate the text bodies, and pass them as "Context" to your AI prompt. This ensures the bot "remembers" what was said earlier in the session.

Quality Assurance (QA) Auditing

Managers can use this endpoint to review agent performance. By fetching the history of "Closed Tickets," you can calculate "Time to Resolution" and evaluate the tone/accuracy of responses.


⚠️ Important Considerations

  • Temporary Files: When downloadMedia is true, the engine uses temporary disk space to decrypt the file. Ensure your hosting environment has sufficient temporary storage if you expect high-volume media downloads.
  • Expired Media: WhatsApp's CDN eventually deletes older media files (usually after 30-60 days). If a message is very old, the download may fail with a Media Not Found error even if the message metadata exists.
  • Group Context: In groups, the message object includes the author (the JID of the participant who sent the message). Use this to identify who said what within a group thread.

Summary of Capabilities:

  • Robust retrieval of conversational history for individuals and groups.
  • Granular control over media downloading to optimize bandwidth.
  • Native support for all WhatsApp message types and metadata.
  • Integrated pagination logic for seamless infinite-scroll interfaces.

Request Parameters

Configure the parameters required to interact with this endpoint. All query and body arguments are listed below with their details.

URL Parameters

Passed in the URL query string
string

WhatsApp Instance ID

Example:
string

API Access Token

Example:
string

Target Chat ID (phone@c.us or group@g.us)

Example:
number

Number of messages to retrieve

Example:
number

Number of messages to skip

Example:
boolean

Whether to download and return media content

Example:

Request Samples

Use these ready-to-go code snippets to integrate our API into your project quickly and efficiently. Choose your preferred language and library.

1const baseUrl = "https://api.wawp.net";
2const endpoint = "/v2/chats/messages";
3const params = new URLSearchParams({
4 "instance_id": "123456789",
5 "access_token": "YOUR_ACCESS_TOKEN",
6 "chatId": "201234567890@c.us",
7 "limit": "50",
8 "offset": "0",
9 "downloadMedia": "true"
10}).toString();
11
12
13fetch(`${baseUrl}${endpoint}${params ? '?' + params : ''}`, {
14 method: "GET",
15 headers: { "Content-Type": "application/json" },
16
17})
18 .then(async (response) => {
19 if (response.ok) {
20 const data = await response.json();
21 console.log("Success:", data);
22 return data;
23 }
24
25 // Error Handling
26 if (response.status === 400) {
27 console.error("Error 400: Bad Request - Missing Required Parameter(s)");
28 }
29 if (response.status === 400) {
30 console.error("Error 400: Bad Request (XML Format)");
31 }
32 if (response.status === 400) {
33 console.error("Error 400: Bad Request (Plain Text)");
34 }
35 if (response.status === 401) {
36 console.error("Error 401: Unauthorized - Invalid or Missing Access Token");
37 }
38 if (response.status === 401) {
39 console.error("Error 401: Unauthorized (XML Format)");
40 }
41 if (response.status === 404) {
42 console.error("Error 404: Not Found - Session Does Not Exist");
43 }
44 if (response.status === 404) {
45 console.error("Error 404: Not Found (XML Format)");
46 }
47 if (response.status === 500) {
48 console.error("Error 500: Internal Server Error - Unexpected Failure");
49 }
50 if (response.status === 500) {
51 console.error("Error 500: Internal Server Error (HTML)");
52 }
53 if (response.status === 502) {
54 console.error("Error 502: Bad Gateway - Connection Failed to Upstream");
55 }
56 if (response.status === 502) {
57 console.error("Error 502: Bad Gateway (XML Format)");
58 }
59
60 const errorText = await response.text();
61 console.error(`Error ${response.status}: ${errorText}`);
62 })
63 .catch((error) => console.error("Network Error:", error));
Interactive Samples
Ln 63, Col 1javascript

Expected Responses

Explore all possible responses and outcomes from the server. We have documented each status code with data examples to make success and error handling easier.

Success - Request completed successfully
Type:
application/json
boolean *
string *

Example

{
"success": true,
"message": "Operation completed successfully"
}
Bad Request - Missing Required Parameter(s)
Unauthorized - Invalid or Missing Access Token
Not Found - Session Does Not Exist
Internal Server Error - Unexpected Failure
Bad Gateway - Connection Failed to Upstream
Previous TopicGet chat picture
Next TopicMark as read

Command Palette

Search for a command to run...