v1

latestSwagger 2.02026-07-13151175.7 KB
Webhooks

Create a webhook

A webhook is an URL that you can register when you want the BulkSMS system to notify you about your messages. You can register multiple webhooks, and each one will be called. (Note: you can also use our Web App to manage your webhooks interactively.)
If you want to be notified of SENT messages and RECEIVED messages you need to create two webhooks.

Implementing your webhook

Code samples of Webhook implementations:

  • PHP

When you implement your webhook, there are a few rules to be aware of:

  • Your webhook must process POST requests that contains an array of messages in the post body. This input given to your webhook has the same structure as the output produced when you call Retrieve Messages.
  • When you register or update your webhook, the URL will be tested by invoking it with an empty array ([]).
  • It is possible for your webhook to receive multiple updates for the same message and status. It happens from time to time that the mobile network duplicates status updates.
  • The order by which the webhook is invoked can be unexpected. For example, if sender A replies before sender B, your webhook might get the reply from B first.
  • The webhook is expected to comply with good practices with regard to the status code it responds with.
    • A status code in the 1xx and 2xx range is taken as an acknowledgement that the invocation was received and that the webhook host is ready to receive another.
    • A status code in the 4xx range is taken as a permanent problem and indicates that the webhook cannot process the message. The specific message that caused the error will be discarded, but your webhook will be invoked again when another message becomes available.
    • Any other status code will be taken as a temporary problem; and indicates that the BulkSMS system should retry. The specific message that caused the error will not be discarded and your webhook will be invoked again with this message (see the subsequent section for more details on retry processing).
  • Your webhook has to respond within 30 seconds. If no response is given in this time, the invocation will be retried.
  • It is good idea to add a secret to your URL in order to make it more secure. Here is an example: https://www.example.com/hook.php?secret=pass763265word
  • You can use a non-standard port if necessary, for example: https://www.example.com:8321/hook.php?secret=pass763265word
  • Your webhook can be called from a dynamic range of IP addresses, and you should be prepared to accept that the source IP can change in the future, without notice. This practice has become common with cloud-hosted solutions. If this is an insurmountable problem for your organisation, please contact support.

Testing and troubleshooting

Use curl to test your webhook. The command below is a template that shows how the BulkSMS system invokes your code. It must return 200 for your URL before you can register it as a webhook.

curl -i -X POST 'YOUR_URL_HERE' --header 'Content-Type: application/json' --header 'User-Agent: BulkSMS Invoker' --data-raw '[]'

When a 200 is returned for an empty array, modify the template to post multiple messages by adding JSON between the square brackets ('[]').

After your webhook is successfully registered, you can send a message to 1111111 for an end-to-end test. The delivery to this test number will fail, but your webhook will be invoked (and there are no charges).

The retry process

The process the BulkSMS systems follow to handle retries is roughly the following:

  • The first retry is scheduled for 90 seconds into the future.
  • After the first retry, subsequent failures will have longer delays, following this sequence - 3 minutes, 6 minutes, 12 minutes thereafter the message will be retried every 15 minutes for a 2 day period.
  • When all retries fail, the message will be discarded.

Problem reports via email

Your are strongly advised to provide an email address when you register your webhook. A notice will be sent to this email address to keep you in the loop whenever there are problems with your webhook. In order to prevent your inbox from being flooded, the system sends a notice about an observed error no more than once in a 24 hour period.

The following emails can be expected

  • A message retrying email is sent after an invocation has failed with a retry-able error. This email is an early warning, allowing you to investigate your systems.
  • A message discarded email is sent after failure email is send when a message is discarded as a consequence of a non-retry-able error.
post/webhooks

Request body

namestring required

A text identifier for the webhook. More than one webhook cannot have the same name.

urlstring required

The location of the webhook.

In addition to being a valid URI, the url must also start with http or https.

contactEmailAddressstring

The email address to which emails will be sent if there are problem with invoking the webhook.

The value must be a valid email address. If this value is null, no email will be sent.

It is null by default.

triggerScope'SENT' | 'RECEIVED' required

Specifies when the webhook will be triggered.

Please note the values are case sensitive.

If the value is SENT, the webhook will be called when a status update becomes available for a message you sent (i.e. a mobile terminating (MT) message).

If the value is RECEIVED, the webhook will be called when a message is received (i.e. a mobile originating (MO) message).

Note that this field forces you to create two separate webhook entries if you want to collect all messages. However, you can use the same url for both webhooks if you want.

invokeOption'ONE' | 'MANY'

Specifies how to invoke your webhook.

If the value is ONE the array POSTed to your webhook will contain no more than a single message. Use this option if your webhook logic is unable to handle more than one messages at a time.

If the value is MANY the array POSTed to your webhook can contain up to 10 messages. This is the recommended option. The number of calls made to your webhook would be less and this will speed up your total processing time. If your webhook fails for an invoke that has more than one message, each message in the array will automatically be retried one at a time.

This value defaults to ONE - but it is recommended that you set this property to MANY.

activeboolean

Indicates whether you want the webhook activated.

If the value is true, the webhook at the given url will be invoked with an empty array ([]) as part of the validation process. If the webhook responds with a 2xx status code, the submission is accepted; if not the webhook is not created (or updated).

If the value is false the webhook will be inactive, and it will not be invoked when messages are SENT or RECEIVED.

The default value is true.

onWebAppboolean

Indicates whether you want to show this webhook on the Web App.

Webhooks shown there can be updated by the user that use the public Web site.

The default value is true.

Example request

{
  "name": "My MT Webhook",
  "url": "https://www.example.com",
  "contactEmailAddress": "tech_team@example.com",
  "triggerScope": "SENT",
  "invokeOption": "MANY",
  "active": true,
  "onWebApp": true
}

Response

Contains the webhook you created

idnumber
namestring
urlstring
contactEmailAddressstring
triggerScopestring
activeboolean
onWebAppboolean

Example response

{
  "id": 234,
  "name": "My MT Webhook",
  "url": "https://www.example.com",
  "contactEmailAddress": "tech_team@example.com",
  "triggerScope": "SENT",
  "active": true,
  "onWebApp": true
}