Skip to content

ArchiveChat#

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

Request#

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

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

For APIUrl, idInstance and apiTokenInstance request parameters, refer to Before you start section.

Note

In order for the method to function, the system must be able to see incoming messages. To enable this, activate the Receive webhooks on incoming messages and files option in the instance settings or use the SetSettings method.

Request parameters#

Parameter Type Mandatory Description
chatId string Yes User or group chat Id

Request body example#

{
    "chatId": "120363043968066561@g.us"
}

Response#

Response parameters#

The response body is empty. If successful, the server response is 200.

ArchiveChat errors#

For a list of errors common to all methods, refer to Common errors section

HTTP code Error identifier Description
400 "ArchiveChatError: cannot archive chat cause last message not found in chat" chatID is false or there is no message in the chat

Request examples#

import requests

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

payload = "{\r\n    \"chatId\": \"120363043968066561@g.us\"r\n}"
headers = {
  'Content-Type': 'application/json'
}

response = requests.request("POST", url, headers=headers, data = 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("https://api.greenapi.com")
    .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("https://api.greenapi.com")
    .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 idInstance and apiTokenInstance values are available in your account, 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