Retrive list of messages

Get a list of messages for a specific chat.

get
messages/:chatId

https://api.mercury.chat/sdk/v1/whatsapp/messages/:chatId?api_token=tokenAPI&instance=instance_number&limit=5&skip=0
Get a list of messages for a specific chat. For more information on pagination, refert to the "Pagination" section.
Request
Response
Request
Path Parameters
chatId
required
string
Is the chat id of the chat to get messages (like chat.chatId)
Query Parameters
skip
optional
number
Number of messages to skip (see the "Pagination" section)
limit
optional
number
Number of messages to return (see the "Pagination" section)
instance
required
string
The Instance number
api_token
required
string
The API token
Response
200: OK
In "data" there is a list of object message.
{
"object": "list",
"data": [
{
"_id": "5cece2439ce23ae3e3cc03dd",
"message_id": "true_44559885894@c.us_3EB0DF93950AEC219153",
"istance_number": "43279",
"body": "text message test",
"body_translate": null,
"type": "chat",
"senderName": "george",
"fromMe": true,
"author": "445566778899@c.us",
"time": 1559028291,
"chatId": "44556634555@c.us",
"messageNumber": 201,
"queueNumber": null,
"status_queued": true,
"status_queued_time": 1559028290,
"status_sent": true,
"status_sent_time": 1559028292,
"status_delivered": true,
"status_delivered_time": 1559028293,
"status_viewed": true,
"status_viewed_time": 1559028296
},
{
"_id": "5cece2179ce23ae3e3cc01e1",
"message_id": "false_4455443344@c.us_3A3FAC46B4641816F1DF",
"istance_number": "43279",
"body": "Hello",
"body_translate": null,
"type": "chat",
"senderName": "george",
"fromMe": false,
"author": "44556665544@c.us",
"time": 1559028245,
"chatId": "44556634555@c.us",
"messageNumber": 200,
"queueNumber": null,
"status_queued": null,
"status_queued_time": null,
"status_sent": null,
"status_sent_time": null,
"status_delivered": null,
"status_delivered_time": null,
"status_viewed": null,
"status_viewed_time": null
},
{
"_id": "5cece20e9ce23ae3e3cc0165",
"message_id": "false_393200427628@c.us_3A12FA6574B6775EF667",
"istance_number": "43279",
"body": "https://storage.googleapis.com/393245903518/2019%252F5%252F28%252Fb2d75754-a742-4977-b86a-6ba466c3b707.oga",
"body_translate": null,
"type": "ptt",
"senderName": "george",
"fromMe": false,
"author": "445566574884@c.us",
"time": 1559028235,
"chatId": "44556634555@c.us",
"messageNumber": 199,
"queueNumber": null,
"status_queued": null,
"status_queued_time": null,
"status_sent": null,
"status_sent_time": null,
"status_delivered": null,
"status_delivered_time": null,
"status_viewed": null,
"status_viewed_time": null
},
{
"_id": "5cece1ef9ce23ae3e3cc001d",
"message_id": "false_44557766574@c.us_3AB22E9A006308D9A806",
"istance_number": "43279",
"body": "https://storage.googleapis.com/393245903518/2019%252F5%252F28%252F06a6a304-bade-47f8-ad35-a14a90006dfc.jpeg",
"body_translate": null,
"type": "image",
"senderName": "george",
"fromMe": false,
"author": "445775664883@c.us",
"time": 1559028200,
"chatId": "44556634555@c.us",
"messageNumber": 198,
"queueNumber": null,
"status_queued": null,
"status_queued_time": null,
"status_sent": null,
"status_sent_time": null,
"status_delivered": null,
"status_delivered_time": null,
"status_viewed": null,
"status_viewed_time": null
},
{
"_id": "5cec03b09ce23ae3e3c3323d",
"message_id": "false_44566577584@c.us_26007CA2AE76CF9A3DB33782FBC5FD29",
"istance_number": "43279",
"body": "[Call - miss]",
"body_translate": null,
"type": "call_log",
"senderName": "george",
"fromMe": false,
"author": "447466455647@c.us",
"time": 1558971300,
"chatId": "44556634555@c.us",
"messageNumber": 197,
"queueNumber": null,
"status_queued": null,
"status_queued_time": null,
"status_sent": null,
"status_sent_time": null,
"status_delivered": null,
"status_delivered_time": null,
"status_viewed": null,
"status_viewed_time": null
}
],
"has_more": true,
"count_api": 2,
"reset_count_api": 43
}
400: Bad Request
GENERIC ERROR

Example:

cURL
C#
Go
Java
NodeJs
Objective-C
PHP
Python
Ruby
Swift
cURL
curl -X GET \
'https://api.mercury.chat/sdk/v1/whatsapp/messages/44373737773@c.us?api_token=tokenAPI&instance=instance_number&limit=5&skip=0'
C#
var client = new RestClient("https://api.mercury.chat/sdk/v1/whatsapp/messages/44373737773@c.us?api_token=tokenAPI&instance=instance_number&limit=5&skip=0");
var request = new RestRequest(Method.GET);
IRestResponse response = client.Execute(request);
Go
package main
import (
"fmt"
"net/http"
"io/ioutil"
)
func main() {
url := "https://api.mercury.chat/sdk/v1/whatsapp/messages/44373737773@c.us?api_token=tokenAPI&instance=instance_number&limit=5&skip=0"
req, _ := http.NewRequest("GET", url, nil)
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
fmt.Println(res)
fmt.Println(string(body))
}
Java
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url("https://api.mercury.chat/sdk/v1/whatsapp/messages/44373737773@c.us?api_token=tokenAPI&instance=instance_number&limit=5&skip=0")
.get()
.build();
Response response = client.newCall(request).execute();
NodeJs
var request = require("request");
var options = { method: 'GET',
url: 'https://api.mercury.chat/sdk/v1/whatsapp/messages/44373737773@c.us',
qs:
{ api_token: 'tokenAPI',
instance: 'instance_number',
limit: '5',
skip: '0' } };
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
});
Objective-C
#import <Foundation/Foundation.h>
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://api.mercury.chat/sdk/v1/whatsapp/messages/44373737773@c.us?api_token=tokenAPI&instance=instance_number&limit=5&skip=0"]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:10.0];
[request setHTTPMethod:@"GET"];
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
if (error) {
NSLog(@"%@", error);
} else {
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;
NSLog(@"%@", httpResponse);
}
}];
[dataTask resume];
PHP
<?php
$request = new HttpRequest();
$request->setUrl('https://api.mercury.chat/sdk/v1/whatsapp/messages/44373737773@c.us');
$request->setMethod(HTTP_METH_GET);
$request->setQueryData(array(
'api_token' => 'tokenAPI',
'instance' => 'instance_number',
'limit' => '5',
'skip' => '0'
));
try {
$response = $request->send();
echo $response->getBody();
} catch (HttpException $ex) {
echo $ex;
}
Python
import requests
url = "https://api.mercury.chat/sdk/v1/whatsapp/messages/44373737773@c.us"
querystring = {"api_token":"tokenAPI","instance":"instance_number","limit":"5","skip":"0"}
payload = ""
response = requests.request("GET", url, data=payload, params=querystring)
print(response.text)
Ruby
require 'uri'
require 'net/http'
url = URI("https://api.mercury.chat/sdk/v1/whatsapp/messages/44373737773@c.us?api_token=tokenAPI&instance=instance_number&limit=5&skip=0")
http = Net::HTTP.new(url.host, url.port)
request = Net::HTTP::Get.new(url)
response = http.request(request)
puts response.read_body
Swift
import Foundation
let request = NSMutableURLRequest(url: NSURL(string: "https://api.mercury.chat/sdk/v1/whatsapp/messages/44373737773@c.us?api_token=tokenAPI&instance=instance_number&limit=5&skip=0")! as URL,
cachePolicy: .useProtocolCachePolicy,
timeoutInterval: 10.0)
request.httpMethod = "GET"
let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
if (error != nil) {
print(error)
} else {
let httpResponse = response as? HTTPURLResponse
print(httpResponse)
}
})
dataTask.resume()