Subscribe to WABA-related events
Posting a request to this endpoint will create a new webhook subscription to the specified event on your WhatsApp Business API (WABA) number.
List of accepted events
Any of these events can be specified as a query parameter in the invocation URL.
info
Check out some of the payload examples.
💡 You can also subscribe and unsubscribe to events manually. Learn more here.
| Event | Description |
|---|---|
whatsapp.waba.message.sent | Triggers when a new WhatsApp message is sent. Example. |
whatsapp.waba.message.receipt.sent | Triggers when a message you sent has been transmitted to the WhatsApp network and is on its way to the recipient. Example. |
whatsapp.waba.message.receipt.received | Triggers when a message you sent is received on the app of its intended receiver. Example. |
Parameters
info
These parameters should be sent as JSON payload in the request body.
| Field | Description |
|---|---|
hook_url | A valid and publicly reachable URL that 2Chat will invoke when the event is triggered |
on_number | The WABA phone number you have configured and connected to 2Chat. Always make sure it is connected |
Invocation
Assume we want to subscribe to the event whatsapp.waba.message.sent as example:
- cURL
- Python
- JavaScript
curl --location --request POST 'https://api.p.2chat.io/open/webhooks/subscribe/whatsapp.waba.message.sent' \
--header 'X-User-API-Key: your_api_key_here' \
--header 'Content-Type: application/json' \
--data-raw '{
"hook_url": "https://www.toptal.com/developers/postbin/1681755466939-3421728690154",
"on_number": "+16173518454"
}'
import requests
import json
url = "https://api.p.2chat.io/open/webhooks/subscribe/whatsapp.waba.message.sent"
payload = json.dumps({
"hook_url": "https://www.toptal.com/developers/postbin/1681755466939-3421728690154",
"on_number": "+16173518454"
})
headers = {
'X-User-API-Key': 'your_api_key_here',
'Content-Type': 'application/json'
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
var axios = require('axios');
var data = JSON.stringify({
"hook_url": "https://www.toptal.com/developers/postbin/1681755466939-3421728690154",
"on_number": "+16173518454"
});
var config = {
method: 'post',
maxBodyLength: Infinity,
url: 'https://api.p.2chat.io/open/webhooks/subscribe/whatsapp.waba.message.sent',
headers: {
'X-User-API-Key': 'your_api_key_here',
'Content-Type': 'application/json'
},
data : data
};
axios(config)
.then(function (response) {
console.log(JSON.stringify(response.data));
})
.catch(function (error) {
console.log(error);
});
Response
The API will return the newly configured webhook if successful.
{
"success": true,
"data": {
"uuid": "WHK530c9d58-2259-4ce2-82a8-1941f3a60665",
"event_name": "whatsapp.waba.message.sent",
"channel_uuid": "WAN95841312-b54d-46e3-b0bc-6414f4a5296b",
"hook_url": "https://www.toptal.com/developers/postbin/1681755466939-3421728690154",
"hook_params": {
"waweb_uuid": "WAN95841312-b54d-46e3-b0bc-6414f4a5296b"
},
"created_at": "2023-04-18T01:58:02Z"
}
}
| Field | Description | Example values |
|---|---|---|
uuid | The unique identifier of the webhook that you will need to make changes to it | WHK530c9d58-2259-4ce2-82a8-1941f3a60665 |
event_name | The name of the event this webhook is subscribed to | whatsapp.waba.message.sent |
channel_uuid | The unique UUID of the WABA channel this webhook is subscribed to | WAN95841312-b54d-46e3-b0bc-6414f4a5296b |
hook_url | The URL 2Chat will call when the event is triggered | https://www.toptal.com/develop... |
hook_params | Custom parameters 2Chat sets to make the webhook functional | {"waweb_uuid": "WAN95841312-b54d-46e3-b0bc-6414f4a5296b"} |
created_at | UTC timestamp for when the webhook was created | 2023-04-18T01:58:02Z |