[go: up one dir, main page]

Skip to content

CreateGroup#

Test Postman

The method is aimed for creating a group chat. When creating a group, it is required to simulate human work. It is required to create a group no more often than 1 group every 5 minutes.

Request#

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

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

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

Request parameters#

Parameter Type Mandatory Description
groupName string Yes New group chat name. The maximum field length is 100 characters
chatIds array Yes Collection of group participants Ids

Request body example#

{
    "groupName": "Group created by Green API",
    "chatIds": [
        "79001234568@c.us",
        "79001234569@c.us"
    ]
}

Response#

Response parameters#

Parameter Type Description
created boolean Group creation flag
chatId string Group chat Id
groupInviteLink string Group invitation link

Response body example#

{
    "created": true,
    "chatId": "11001234567-1587570015@g.us",
    "groupInviteLink": "https://chat.whatsapp.com/xxxxxxxxxxxxxxxxxxxxxx"
}

CreateGroup errors#

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

HTTP code Error Id Description
400 Bad Request
Validation failed
Validation error
500 Error is returned by WhatsApp, restricting the user from creating a group. Try to create a group from a mobile device, you will get a warning: "Failed to create a group because you created too many groups very quickly. Try again later.
500 Internal Server Error One or more chatIds elements specify a group

Request examples#

import requests

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

payload = {(
    "groupName": "Group created by Green API", 
    "chatIds": [  
        "11001234567@c.us", 
        "79001234568@c.us" ])
}
headers = {
  'Content-Type': 'application/json'
}

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

print(response.text.encode('utf8'))
curl --location '{{apiUrl}}/waInstance{{idInstance}}/createGroup/{{apiTokenInstance}}' \
--header 'Content-Type: application/json' \
--data-raw '{
    "groupName": "Group created by Green API TEST",
    "chatIds": [
        "79888888234@c.us",
        "76567666543@c.us"
    ]
}'
var restTemplate = new RestTemplate();
var requestUrl = new StringBuilder();
requestUrl
    .append({{apiUrl}})
    .append("/waInstance").append({{idInstance}})
    .append("/createGroup/")
    .append({{apiTokenInstance}});

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

var jsonBody = "{\"groupName\":\"Group created by Green API TEST\",\"chatIds\":[\"79888888234@c.us\",\"76567666543@c.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("/createGroup/")
    .append({{apiTokenInstance}});

var response = Unirest.post(requestUrl.toString())
    .header("Content-Type", "application/json")
    .body("{\"groupName\":\"Group created by Green API TEST\",\"chatIds\":[\"79888888234@c.us\",\"76567666543@c.us\"]}")
    .asString();

System.out.println(response);
Sub CreateGroup()
    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}}/createGroup/{{apiTokenInstance}}"

    ' groupName is the name of the new group chat, chatIds is a collection of group member IDs
    RequestBody = "{""groupName"":""Group created by Green API"",""chatIds"":[""79001234568@c.us"",""79001234569@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