Skip to main content

Set up numbers to trigger webhooks

Using Mediahawk, you can trigger a webhook to your platform or server when a call hits our system as soon as the call starts ringing. This guide will help you see what webhooks are currently set up and create a new webhook to trigger when a call arrives to your number.

Before you begin this guide, please ensure you have followed the Authenticate guide and have a valid token.

You can download a full working code example for this guide here:

CURL, PHP, Node.js, Python, C#

List out your existing webhooks

First of all, list out your existing webhooks.

apiKey="<API_KEY>"

curl -L -X GET "https://www.reports.mediahawk.co.uk/rest/v2_0/webhooks?api_key=${apiKey}" \
--header "Content-Type: application/json"

Create a new webhook

Create a new webhook that will send a request to your endpoint when any call is received. This is the most basic webhook you can create.

Below, you will find an example payload for a webhook request. This can be customised in the webhook:

{
"CallID": "12345",
"ServiceNumber": "01234567890",
"CallersNumber": "01234567890",
"TerminatingNumber": "01234567890",
"CallStart": "2022-01-01 13:12:00",
"CampaignDescription": "My Campaign",
"LastSource": "google",
"LastMedium": "ppc",
"FirstSource": "direc",
"FirstMedium": "direct",
"FirstKeyword": "mediahawk",
"Keyword": "mediahawk",
"VisitorID": "12345",
"GoogleClickID": "123467",
"MediaChannel": "My Channel",
"MediaOwner": "My Owner",
"MediaDescription": "My Description",
"Department": "My Department",
"CallTags": "utm_content=abc",
"CallRef": "23456",
"PageURI": "http://www.example.com/full/urls",
"PageTitle": "My page title",
"LandingPageURI": "http://www.example.com/full/urls",
"LandingPageTitle": "My page title",
"PaidSearchType": "1",
"PaidSearchMatchType": "Broad",
"PaidSearchAdGroupID": "356356356",
"PaidSearchAdGroupName": "adgroup name",
"PaidSearchCampaignID": "5757857857",
"PaidSearchCampaignName": "campaign name",
"GoogleClientId": "986977467",
"PoolDescription": "my pool",
"CallMHID": "AFGvfg45HT",
"VisitMHID": "rtGF576fTB",
"VisitorMHID": "sfg53GF87f"
}

To create the webhook. The only thing you have to provide is the endpoint.

apiKey="<API_KEY>"
endpoint="<ENDPOINT>"
curl -L -X POST "https://www.reports.mediahawk.co.uk/rest/v2_0/webhooks?api_key=${apiKey}" \
--header "Content-Type: application/json" \
--header "Accept: application/json" \
--data '{ "endpoint": "'$endpoint'" }'

Customise your webhook to only trigger for specific numbers

If you want your webhook to only trigger for specific numbers or Dynamic Pools, you can do this using the:

  • number_acl - This allows you to allow or deny this webhook for specific static numbers
  • url_acl - This allows you to allow or deny this webhook for specific Dynamic URLs
  • destination_acl - This allows you to allow of deny this webhook for specific destinations
info

The ACLs work by matching (**number_acl** OR **url_acl**) AND **destination_acl** to work out whether to trigger.

Using this request, you can modify the webhook we created earlier to only trigger when a specific number is called, and set it to not send if we are calling a specific destination. We also can set it to email us if there is a problem with the webhook.

apiKey="<API_KEY>"
webhookId="<WEBHOOK_ID>"

# Numbers in E.164 format with no leading plus (e.g. 44111222333)
staticNumber="<STATIC_NUMBER>"
destinationNumber="<DESTINATION_NUMBER>"
failureEmail="<FAILURE_EMAIL>"

curl -L -X PATCH "https://www.reports.mediahawk.co.uk/rest/v2_0/webhooks/${webhookId}?api_key=${apiKey}" \
--header "Content-Type: application/json" \
--header "Accept: application/json" \
--data '{
"failures_email": "'$failureEmail'",
"number_acl": {
"type": "allow",
"service_numbers": [
"'$staticNumber'"
]
},
"destination_acl": {
"type": "block",
"destinations": [
"'$destinationNumber'"
]
}
}'