POST /subscriptions
Creates a new webhook or updates an existing one.
caution
Each account can only register 1 webhook.
Required Parameters
Parameter | Type | Description |
---|---|---|
url | string | The identifier of the contact (e.g. phone number in WhatsApp) |
subscriptions | string[] | Comma separated values of the events to subscribe on this webhook (e.g message_created ) |
Example Request
- cURL
- Node
- Ruby
- Go
- PHP
- Python
curl -X POST "https://api.callbell.eu/v1/webhooks/subscribe" \
-H "Authorization: Bearer test_gshuPaZoeEG6ovbc8M79w0QyM" \
-H "Content-Type: application/json" \
-d '{
"url": "https://my-app.com/my-webhook-endpoint",
"subscriptions": ["message_created", "contact_created"]
}'
import axios from 'axios';
const response = await axios.post(
'https://api.callbell.eu/v1/webhooks/subscribe',
// '{\n "url": "https://my-app.com/my-webhook-endpoint",\n "subscriptions": ["message_created", "contact_created"]\n }',
{
'url': 'https://my-app.com/my-webhook-endpoint',
'subscriptions': [
'message_created',
'contact_created'
]
},
{
headers: {
'Authorization': 'Bearer test_gshuPaZoeEG6ovbc8M79w0QyM',
'Content-Type': 'application/json'
}
}
);
require 'net/http'
require 'json'
uri = URI('https://api.callbell.eu/v1/webhooks/subscribe')
req = Net::HTTP::Post.new(uri)
req.content_type = 'application/json'
req['Authorization'] = 'Bearer test_gshuPaZoeEG6ovbc8M79w0QyM'
# The object won't be serialized exactly like this
# req.body = "{\n \"url\": \"https://my-app.com/my-webhook-endpoint\",\n \"subscriptions\": [\"message_created\", \"contact_created\"]\n }"
req.body = {
'url' => 'https://my-app.com/my-webhook-endpoint',
'subscriptions' => [
'message_created',
'contact_created'
]
}.to_json
req_options = {
use_ssl: uri.scheme == 'https'
}
res = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
http.request(req)
end
package main
import (
"fmt"
"io"
"log"
"net/http"
"strings"
)
func main() {
client := &http.Client{}
var data = strings.NewReader(`{
"url": "https://my-app.com/my-webhook-endpoint",
"subscriptions": ["message_created", "contact_created"]
}`)
req, err := http.NewRequest("POST", "https://api.callbell.eu/v1/webhooks/subscribe", data)
if err != nil {
log.Fatal(err)
}
req.Header.Set("Authorization", "Bearer test_gshuPaZoeEG6ovbc8M79w0QyM")
req.Header.Set("Content-Type", "application/json")
resp, err := client.Do(req)
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()
bodyText, err := io.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", bodyText)
}
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.callbell.eu/v1/webhooks/subscribe');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer test_gshuPaZoeEG6ovbc8M79w0QyM',
'Content-Type: application/json',
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{\n \"url\": \"https://my-app.com/my-webhook-endpoint\",\n \"subscriptions\": [\"message_created\", \"contact_created\"]\n }");
$response = curl_exec($ch);
curl_close($ch);
import requests
headers = {
'Authorization': 'Bearer test_gshuPaZoeEG6ovbc8M79w0QyM',
'Content-Type': 'application/json',
}
json_data = {
'url': 'https://my-app.com/my-webhook-endpoint',
'subscriptions': [
'message_created',
'contact_created',
],
}
response = requests.post('https://api.callbell.eu/v1/webhooks/subscribe', headers=headers, json=json_data)
# Note: json_data will not be serialized by requests
# exactly as it was in the original request.
#data = '{\n "url": "https://my-app.com/my-webhook-endpoint",\n "subscriptions": ["message_created", "contact_created"]\n }'
#response = requests.post('https://api.callbell.eu/v1/webhooks/subscribe', headers=headers, data=data)
Response
Parameter | Type | Description |
---|---|---|
contact | Webhook | The webhook which was created or updated. |
Example Response
response.json
{
"webhook": {
"url": "https://my-app.com/my-webhook-endpoint",,
"subscriptions": [
"message_created"
],
"createdAt": "2022-10-18 17:01:20 +0200",
"enabled": true
}
}