Create a WhatsApp group
With this endpoint, you will be able to create a new WhatsApp group in your account.
WhatsApp has a non-published soft limit on the number of groups you can create in a time window.
Tests indicate that the limit may be 30 per day. After you reach that limit, attempting to create new groups will fail until the time window gets refreshed.
A few recommendations to follow:
Creating many groups will can be problematic. WhatsApp shadow bans numbers that create many groups and only the app will show you the exact error message when this happens.
When you get an error using this endpoint, try creating the group using WhatsApp Web or the app. It will likely also fail if the number has reached WhatsApp limits.
Don't rely on a single number as the sole administrator and owner of the group. Have backup numbers and build reputation using them from time to time.
WhatsApp groups are the #1 attack vector for spammers and people committing fraud on WhatsApp. Scrutinity has increased which will make using groups more difficult with people who don't have you saved as a contact.
- Always ask participants of your groups to have your main numbers saved as a contact. Create an email campaign, send them a message asking them this, and only after that create the groups. This will decrease the error rates.
Parameters
These parameters should be sent as a JSON payload in the request body.
| Field | Description | Example values |
|---|---|---|
from_number | Your WhatsApp number that you connected to 2Chat | +18647351567 |
group.name | A name for the group you are trying to create | My cool WhatsApp group |
group.description | A description for the group being created. This value is optional | cool group |
group.participants | A list of phone numbers you want to add to the group | [ "+18647351567", "+17137157533"] |
You can create the group with up to 10 participants. If you want to add more than this limit, you can call the Add Participant endpoint after the group is created.
Invocation
- cURL
- Python
- JavaScript
curl -X POST --location 'https://api.p.2chat.io/open/whatsapp/group/create' \
--header 'Content-Type: application/json' \
--header 'X-User-API-Key: your_api_key_here' \
--data '{
"from_number": "+595981048477",
"group": {
"name": "My cool WhatsApp group",
"participants": [
"+17137157533",
"+18647351567"
]
}
}'
import requests
import json
url = "https://api.p.2chat.io/open/whatsapp/group/create"
payload = json.dumps({
"from_number": "+595981048477",
"group": {
"name": "My cool WhatsApp group",
"participants": [
"+17137157533",
"+18647351567"
]
}
})
headers = {
'Content-Type': 'application/json',
'X-User-API-Key': 'your_api_key_here'
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
const axios = require('axios');
let data = JSON.stringify({
"from_number": "+595981048477",
"group": {
"name": "My cool WhatsApp group",
"participants": [
"+17137157533",
"+18647351567"
]
}
});
let config = {
method: 'post',
maxBodyLength: Infinity,
url: 'https://api.p.2chat.io/open/whatsapp/group/create',
headers: {
'Content-Type': 'application/json',
'X-User-API-Key': 'your_api_key_here'
},
data : data
};
axios.request(config)
.then((response) => {
console.log(JSON.stringify(response.data));
})
.catch((error) => {
console.log(error);
});
Response
After the group is created, it can take a few minutes for 2Chat to be able to see it and list it.
Seeing unaccepted_numbers in the reply means that the numbers listed couldn't be added, either because they are invalid or because they don't have a WhatsApp account.
{
"success": true,
"group": {
"name": "My cool WhatsApp group",
"wa_group_id": "120363777777777777@g.us",
"participants":
{
"+595981048477": {
"statusCode": 200,
"message": "The participant was added successfully",
"isGroupCreator": true,
"isInviteV4Sent": false
},
"+17137157533": {
"statusCode": 200,
"message": "The participant was added successfully",
"isGroupCreator": false,
"isInviteV4Sent": false
},
"+18647351567": {
"statusCode": 200,
"message": "The participant was added successfully",
"isGroupCreator": false,
"isInviteV4Sent": false
}
},
"accepted_numbers": [
"+17137157533",
"+18647351567"
],
"unaccepted_numbers": [],
"uuid": "WAG62598186-d2bd-4946-86c6-30f8a3c849c6"
}
}