Create a WhatsApp Notification Subscription With Webhooks

This code snippet shows how to receive WhatsApp Business Account notifications using a webhook.

API Key Scope

Use your master API key credentials when you call this endpoint.

Sub API keys can also create, list, and delete subscriptions. Because subscriptions are tied to the master API key, all sub API keys under that master key share the same subscription data. For example, a subscription created by one sub API key can be listed or deleted by another sub API key under the same master key.

Subscription limits are applied at the master API key level.

Example

Find the description for all variables used in each code snippet below:

KeyDescription
VONAGE_API_KEY

Your Vonage API key (see it on your dashboard).

VONAGE_API_SECRET

Your Vonage API secret (also available on your dashboard).

CHANNEL_MANAGER_WHATSAPP_NOTIFICATION_WEBHOOK_URL_WEB

A custom webhook URL that is setup to accept requests.

Prerequisites

If you do not have an application you can create one. Make sure you also configure your webhooks.

Write the code

Add the following to create-notification-webhook-web-url.sh:

curl -X POST https://api.nexmo.com/v2/whatsapp-manager/subscriptions \
  -u "${VONAGE_API_KEY}:${VONAGE_API_SECRET}" \
  -H 'Content-Type: application/json' \
  -H 'Accept: application/json' \
  -d $'{
    "type": "webhook",
    "webhook": {
      "url": "'${CHANNEL_MANAGER_WHATSAPP_NOTIFICATION_WEBHOOK_URL_WEB}'"
    }
  }'

View full source

Run your code

Save this file to your machine and run it:

bash create-notification-webhook-web-url.sh

Try it out

When you run the code you will be subscribed to updates for changes to your WhatsApp business account, and you will begin to receive notifications at your custom webhook URL.