Add a participant to a WhatsApp group
With this endpoint, you will be able to add a phone number as a participant in an existing WhatsApp group
Parameters
You will need to obtain the UUID of the WhatsApp group to which you want to add the new participant. For this example, we will use WAG45b0f301-9203-4660-8b57-b51a6c2742a5
as the UUID.
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 | +12123334444 |
participants | A list of phone numbers you want to add to the group | [ "+447700176576", "+17137157533"] |
You can add up to 10 participants per invocation. If you want to add more than 10 people, you can call this endpoint multiple times.
Invocation
The group UUID is part of the path in the URL. For this example, we'll use WAG45b0f301-9203-4660-8b57-b51a6c2742a5
as the UUID.
You can obtain the UUID of the group you want to target using the List Groups endpoint
- cURL
- Python
- NodeJS
- PHP
curl -X POST --location 'https://api.p.2chat.io/open/whatsapp/group/WAG45b0f301-9203-4660-8b57-b51a6c2742a5/add-participant' \
--header 'Content-Type: application/json' \
--header 'X-User-API-Key: your_api_key_here' \
--data '{
"from_number": "+12123334444",
"participants": [
"+447700176576",
"+17137157533"
]
}'
import requests
import json
url = "https://api.p.2chat.io/open/whatsapp/group/WAG45b0f301-9203-4660-8b57-b51a6c2742a5/add-participant"
payload = json.dumps({
"from_number": "+12123334444",
"participants": [
"+447700176576",
"+17137157533"
]
})
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": "+12123334444",
"participants": [
"+447700176576",
"+17137157533"
]
});
let config = {
method: 'post',
maxBodyLength: Infinity,
url: 'https://api.p.2chat.io/open/whatsapp/group/WAG45b0f301-9203-4660-8b57-b51a6c2742a5/add-participant',
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);
});
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.p.2chat.io/open/whatsapp/group/WAG45b0f301-9203-4660-8b57-b51a6c2742a5/add-participant',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => '{
"from_number": "+12123334444",
"participants": [
"+447700176576",
"+17137157533"
]
}',
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json',
'X-User-API-Key: your_api_key_here'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
Response
After the participants are added, it can take a few minutes for 2Chat to be able to see the changes made.
Seeing unaccepted_numbers
in the reply means that the numbers listed couldn't be processed, either because they are invalid or because they don't have a WhatsApp account.
{
"success": true,
"participants": {
"+447700176576": {
"statusCode": 200,
"message": "The participant was added successfully",
"isInviteV4Sent": false
},
"+17137157533": {
"statusCode": 200,
"message": "The participant was added successfully",
"isInviteV4Sent": false
}
}
}