Create a WhatsApp channel
With this endpoint, you will be able to create a new WhatsApp channel in your account.
Parameters
These parameters should be sent as a JSON payload in the request body.
Field | Description | Example values |
---|---|---|
phone_number | The number you want to connect to 2Chat | +18647351567 |
friendly_name | A name or alias for the number | My business number |
Invocation
- cURL
- Python
- NodeJS
curl -X POST --location 'https://api.p.2chat.io/open/whatsapp/channel/create' \
--header 'Content-Type: application/json' \
--header 'X-User-API-Key: your_api_key_here' \
--data '{
"phone_number": "+18647351567",
"friendly_name": "Testing number creation"
}'
import requests
import json
url = "https://api.p.2chat.io/open/whatsapp/channel/create"
payload = json.dumps({
"phone_number": "+18647351567",
"friendly_name": "Testing number creation"
})
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({
"phone_number": "+18647351567",
"friendly_name": "Testing number creation"
});
let config = {
method: 'post',
maxBodyLength: Infinity,
url: 'https://api.p.2chat.io/open/whatsapp/channel/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
If the number didn't exist and the creation was successful, you will see the following output and immediately after the number will try to connect and generate a QR code that you will need to scan.
To get that QR code information you need to call the Channel Status Endpoint using the UUID
value (WPNf3ea6c85-0dca-4d8a-a9a6-2b918f59cc97
) you obtained in this step.
tip
You can also get the UUID of a number you want to manipulate with the List Numbers Endpoint.
{
"success": true,
"channel": {
"id": "WPNf3ea6c85-0dca-4d8a-a9a6-2b918f59cc97",
"uuid": "WPNf3ea6c85-0dca-4d8a-a9a6-2b918f59cc97",
"friendly_name": "Testing number creation now",
"phone_number": "+18647351566",
"iso_country_code": "US",
"pushname": null,
"server": null,
"platform": null,
"connection_status": "D",
"enabled": true,
"is_business_profile": false,
"channel_type": "WW",
"sync_contacts": false,
"timezone": "America/New_York",
"lang": "en",
"created_at": "2023-10-12T17:43:58Z",
"updated_at": null
}
}