Create a WhatsApp group
With this endpoint, you will be able to create a new WhatsApp group in your account.
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.participants | A list of phone numbers you want to add to the group | [ "+18647351567", "+17137157533"] |
Invocation
- cURL
- Python
- NodeJS
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
info
After the group is created, it can take a few minutes for 2Chat to be able to see it and list it.
{
"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
}
},
"success": true
}
}