Skip to content

ArchiveChat#

Test Postman

The method archives a chat. You can archive chats that have at least one incoming message.

Request#

To archive a chat, you need to execute a request at:

POST
{{apiUrl}}/waInstance{{idInstance}}/archiveChat/{{apiTokenInstance}}

To get the apiUrl, idInstance and apiTokenInstance request parameters, refer to the Before you start section.

Note

For the method to work, the system must see incoming messages. To do this, enable Receive notifications about incoming messages and files in the instance settings or use the SetSettings method

Request parameters#

Parameter Type Required Description
chatId string Yes Chat or group chat identifier

Request body example#

{
    "chatId": "-10000000000000"
}

Response#

Response fields#

The response body is empty. On success the server responds with 200.

archiveChat errors#

For the list of errors common to all methods, see the Common errors section

HTTP code Error identifier Description
400 Bad Request
Validation failed
Validation error
400 "archiveChatError: cannot archive chat cause last message not found in chat" chatID is incorrect or there are no messages in the chat
400 Bad Request
archiveChatError: chat with id 71234567890@c.us already archive=true
The chat is already archived
400 Bad Request
archiveChatError: chat with id 71234567890@c.us not found
The specified number is not in the contacts
400 Validation failed.
Details: 'value' must have at least 1 key
Validation error. The value field must contain at least 1 character
500 Internal Server Error
interface conversion: interface {} is bool, not string
Incorrect data type of the chatId field

Code examples#

import requests

url = "{{apiUrl}}/waInstance{{idInstance}}/archiveChat/{{apiTokenInstance}}"

payload = {(
    "chatId": "79876543210@c.us")
}
headers = {
    'Content-Type': 'application/json'
}

response = requests.post(url, json=payload)

print(response.text.encode('utf8'))
curl --location '{{apiUrl}}/waInstance{{idInstance}}/archiveChat/{{apiTokenInstance}}' \
--header 'Content-Type: application/json' \
--data-raw '{
    "chatId": "120363043968066561@g.us"
}'
var restTemplate = new RestTemplate();
var requestUrl = new StringBuilder();
requestUrl
    .append({{apiUrl}})
    .append("/waInstance").append({{idInstance}})
    .append("/archiveChat/")
    .append({{apiTokenInstance}});

var headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);

var jsonBody = "{\"chatId\": \"120363043968066561@g.us\"}";

var requestEntity = new HttpEntity<>(jsonBody, headers);

var response = restTemplate.exchange(requestUrl.toString(), HttpMethod.POST, requestEntity, String.class);
System.out.println(response);
var requestUrl = new StringBuilder();
requestUrl
    .append({{apiUrl}})
    .append("/waInstance").append({{idInstance}})
    .append("/archiveChat/")
    .append({{apiTokenInstance}});

var response = Unirest.post(requestUrl.toString())
    .header("Content-Type", "application/json")
    .body("{\"chatId\": \"120363043968066561@g.us\")
    .asString();

System.out.println(response);
Sub archiveChat()
    Dim url As String
    Dim RequestBody As String
    Dim http As Object
    Dim response As String

    ' The apiUrl, idInstance and apiTokenInstance values are available in console, double brackets must be removed
    url = "{{apiUrl}}/waInstance{{idInstance}}/archiveChat/{{apiTokenInstance}}"

    ' ChatId - number to send the chat to the archive (@c.us for private chats, @g.us for group chats)
    RequestBody = "{""chatId"":""70123456789@c.us""}"

    Set http = CreateObject("MSXML2.XMLHTTP")

    With http
        .Open "POST", url, False
        .setRequestHeader "Content-Type", "application/json"
        .Send RequestBody
    End With

    response = http.responseText

    Debug.Print response

    ' Outputting the answer to the desired cell
    Range("A1").Value = response

    Set http = Nothing
End Sub