
Webhooks for outbound SMS
Here’s how to use Plivo APIs to send SMS messages from your web application and include a callback URL. Before you get started, you must buy an SMS-enabled Plivo phone number to send messages to the US and Canada. You can purchase numbers from Phone Numbers > Buy Number section of the Plivo console, or by using the Numbers API.
Code
-
Replace the
auth_id
andauth_token
placeholders with your authentication credentials, which you can find on the Overview screen of the Plivo console. -
Replace the
src
placeholder with the phone number you purchased anddst
with the phone number you’ll be sending SMS messages to. Both should be in E.164 format. -
Replace
https://yourdomain.com/sms_status/
with the webhook URL you’ve set up. - If you’re using a Plivo trial account, you can send SMS messages only to phone numbers that have been verified with Plivo. You can verify phone numbers through the Phone Numbers Sandbox Numbers page.
Webhooks for inbound SMS
See the receive SMS usage guide for more information about how to receive SMS messages on a two-way SMS-enabled Plivo phone number.Handle callbacks in your web app
To handle callbacks in your app, your endpoint should:- Capture HTTP requests
- Respond to the requests
Note: Plivo automatically retries webhooks three times if an HTTP 200 status code is not returned:
- First at 60 seconds after the original attempt.
- Second at 120 seconds after the first retry attempt.
- Third at 240 seconds after the second retry attempt.
Test and validate
Let’s take a look at an example. Typically, you would include a URL that points to your web app, but we’ll use a URL from RequestBin, a service that lets you collect, analyze, and debug HTTP requests, so we can check the callbacks.- Create a new bin in RequestBin.
- Replace the “url” placeholder with the URL of the new bin.
- Run the code that appear above. You should receive the SMS message on the phone number defined in destination field, and see callback requests in RequestBin similar to the screenshots below for callback events such as queued, sent, and delivered.
Queued status callback

Sent status callback

Delivered status callback

- Callbacks for incoming messages work in the same manner as outbound messages.
- You should also receive statuses such as undelivered or failed, and some messages may remain in the sent state. See more information about our different SMS statuses.