Build Webhooks

Write the code that properly handles webhook notifications.

The first step to adding webhooks to your SMSPortal integration is to build your own custom endpoint. Creating a webhook endpoint on your server is no different from creating any page on your website.

Before looking at the code, there are two different versions of webhooks. To learn more about which webhooks version each API or channel uses, and how to set them up with your application, please see the table below. You should also review the best practices.

ChannelMethod
REST APIWebhooks V2 (POST)
SFTP Version 7Webhooks V2 (POST)
WebsiteWebhooks V1 (GET)
Legacy APIsWebhooks V1 (GET)
Short CodesWebhooks V1 (GET)
URL TrackingWebhooks V1 (GET)

Return a 2xx status code quickly

To acknowledge receipt of an event, your endpoint must return a 2xx HTTP status code to SMSPortal. All response codes outside this range, including 3xx codes, indicate to SMSPortal that you did not receive the event.

If SMSPortal does not receive a 2xx HTTP status code, the notification is retried. After 5 failures to send the notification, SMSPortal marks the event as failed and stops trying to send it to your endpoint.

Because properly acknowledging receipt of the webhook notification is so important, your endpoint should return a 2xx HTTP status code prior to any complex logic that could cause a timeout.

Test that your endpoint works

As your webhook endpoint is used asynchronously, its failures may not be obvious to you until it’s too late. Always test that your endpoint works:

  • Upon initial creation
  • After taking it live
  • After making any changes

The Test Webhooks page explains how to test your endpoint.