Set a chat as read

Use this API to make users see their messages read and reset the unread count.

patch
readChat/:chatId

https://api.mercury.chat/sdk/v1/whatsapp/readChat/:chatId?api_token=tokenAPI&instance=instance_number
Use this method to make users see their messages read and reset unread count (chat.count_message_read).
Request
Response
Request
Path Parameters
chatId
required
string
The chat id (like chat.chatId)
Query Parameters
instance
required
string
The instance number
api_token
required
string
The API token
Response
200: OK
In "data" there is a chat.
{
"object": "chat_whatsapp",
"data": {
"_id": "5cebb9e09ce23ae3e3bffcc4",
"istance_number": "43279",
"last_message_time": 1558955671,
"last_message_number": 194,
"last_message_number_id": "5cebc69b9ce23ae3e3c09962",
"count_message_read": 0,
"chatId": "443345674844@c.us",
"name": "George",
"image": "https://storage.googleapis.com/393245903518/60281896_2563248167033379_8987400469118713856_n.jpg",
"metadata": {
"isGroup": false,
"participants": [],
"groupInviteLink": null
}
},
"has_more": false,
"count_api": 1,
"reset_count_api": 60
}
400: Bad Request
GENERIC ERROR

Example:

cURL
C#
Go
Java
NodeJs
Objective-C
PHP
Python
Ruby
Swift
cURL
curl -X PATCH \
'https://api.mercury.chat/sdk/v1/whatsapp/readChat/443374664755@c.us?api_token=tokenAPI&instance=instance_number'
C#
var client = new RestClient("https://api.mercury.chat/sdk/v1/whatsapp/readChat/443374664755@c.us?api_token=tokenAPI&instance=instance_number");
var request = new RestRequest(Method.PATCH);
IRestResponse response = client.Execute(request);
Go
package main
import (
"fmt"
"net/http"
"io/ioutil"
)
func main() {
url := "https://api.mercury.chat/sdk/v1/whatsapp/readChat/443374664755@c.us?api_token=tokenAPI&instance=instance_number"
req, _ := http.NewRequest("PATCH", 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/readChat/443374664755@c.us?api_token=tokenAPI&instance=instance_number")
.patch(null)
.build();
Response response = client.newCall(request).execute();
NodeJs
var request = require("request");
var options = { method: 'PATCH',
url: 'https://api.mercury.chat/sdk/v1/whatsapp/readChat/443374664755@c.us',
qs: { api_token: 'tokenAPI', instance: 'instance_number' } };
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/readChat/443374664755@c.us?api_token=tokenAPI&instance=instance_number"]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:10.0];
[request setHTTPMethod:@"PATCH"];
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
HttpRequest::methodRegister('PATCH');
$request = new HttpRequest();
$request->setUrl('https://api.mercury.chat/sdk/v1/whatsapp/readChat/443374664755@c.us');
$request->setMethod(HttpRequest::HTTP_METH_PATCH);
$request->setQueryData(array(
'api_token' => 'tokenAPI',
'instance' => 'instance_number'
));
try {
$response = $request->send();
echo $response->getBody();
} catch (HttpException $ex) {
echo $ex;
}
Python
import requests
url = "https://api.mercury.chat/sdk/v1/whatsapp/readChat/443374664755@c.us"
querystring = {"api_token":"tokenAPI","instance":"instance_number"}
payload = ""
response = requests.request("PATCH", url, data=payload, params=querystring)
print(response.text)
Ruby
require 'uri'
require 'net/http'
url = URI("https://api.mercury.chat/sdk/v1/whatsapp/readChat/443374664755@c.us?api_token=tokenAPI&instance=instance_number")
http = Net::HTTP.new(url.host, url.port)
request = Net::HTTP::Patch.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/readChat/443374664755@c.us?api_token=tokenAPI&instance=instance_number")! as URL,
cachePolicy: .useProtocolCachePolicy,
timeoutInterval: 10.0)
request.httpMethod = "PATCH"
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()