Skip to content

LeaveGroup#

The method makes the current account user leave the group chat.

Request#

To leave a group chat, you have to execute a request at:

POST https://api.greenapi.com/waInstance{{idInstance}}/leaveGroup/{{apiTokenInstance}}

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

Request parameters#

Parameter Type Mandatory Description
groupId string Yes Group chat Id, which you'd like to leave.

Request body example#

{
    "groupId": "11001234567-1587570015@g.us"
}

Response#

Response parameters#

Parameter Type Description
leaveGroup boolean Leave group flag

Response body example#

{
    "leaveGroup": true
}

LeaveGroup errors#

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

Request examples#

import requests

url = "https://api.greenapi.com/waInstance{{idInstance}}/leaveGroup/{{apiTokenInstance}}"

payload = "{\r\n    \"groupId\": \"11001234567-1587570015@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 'https://api.green-api.com/waInstance{{idInstance}}/leaveGroup/{{apiTokenInstance}}' \
--header 'Content-Type: application/json' \
--data-raw '{
    "groupId": "112121212121212@g.us"
}'
var restTemplate = new RestTemplate();
var requestUrl = new StringBuilder();
requestUrl
    .append("https://api.greenapi.com")
    .append("/waInstance").append({{idInstance}})
    .append("/leaveGroup/")
    .append({{apiTokenInstance}});

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

var jsonBody = "{\"groupId\": \"11111111111111111@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("/leaveGroup/")
    .append({{apiTokenInstance}});

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

System.out.println(response);