Webhooks
Bandwidth uses HTTP Callbacks webhooks to send events to any publicly addressable url, as defined in your messaging application.
Overview
- All Message callbacks are sent as a list/array
[ {message metadata} ]
to the webhook url in the application. - You MUST Reply with a
HTTP 2xx
status code for every callback/delivery receipt. Bandwidth will retry every callback over the next 24 hours until aHTTP 2xx
code is received for the callback. After 24 hours, Bandwidth will no longer try to send the callback. - Bandwidth's Messaging platform has a 10 second timeout for callbacks. This means your server must respond to the callback request within 10 seconds, otherwise the platform will try again at a later time.
- Because we guarantee "at least once delivery" of events, it is possible (but not common) to receive duplicate message events. Your server should be able to handle duplicates.
Inbound Message Webhooks
For incoming messages sent to your numbers, a callback will also be received, notifying your Application of the incoming message. For group messages where you own multiple recipient phone numbers, you will receive a distinct event and messageId
for each individual recipient.
In order to receive text messages events, you need to ensure you have set up your application to send callbacks to your server's URL
When sending to Group Messages, there is a maximum of 10 participants in a Group.
For inbound messages, we do not limit the amount of recipients. We will pass along any messages we receive, even if there are more than 10 recipients.
If you wanted to reply to all 9+{n}
recipients using V2 APIs, Bandwidth will reply with a 400 error (as you are limited to 10 recipients when sending outbound). You will need to break up the responses into separate messages to respond to more than 9+{n}
participants
Message Received
You will receive this webhook when a message is sent to a message-enabled Bandwidth telephone number on your account.
Request Parameters
Parameter | Type | Description |
---|---|---|
type | string | The Event type |
time | string | The time of the event described in the receipt |
description | string | A detailed description of the event described by the receipt |
to | string | The destination number for an outbound message receipt |
message | Object | An object of message information |
message.id | string | The unique ID of this message |
message.owner | string | The phone number this particular message is associated with. For an outbound message, this is always the from number.For an inbound message, this will be (one of) the to number(s).For instance, if this is an inbound group message, the owner field will be set to the to number that this particular copy of the group message belongs to. |
message.time | string | The time stamp of when message was created |
message.direction | string | Whether the message was sent from Bandwidth, or received by a Bandwidth number |
message.to | array | The phone number (or numbers) the message the message is sent to. On a POST, this can be a String, or an array of one or more numbers. In all other places, this will be an array. |
message.from | string | The phone number the message was sent from |
message.text | string | The text content of the message |
message.applicationId | string | The ID of the Application your from number is associated with. |
message.media | array | A list of URLs to include as media attachments as part of the message. Using the v2 media api you can download the media WITHIN 2 DAYS The URL will look something like: https://messaging.bandwidth.com/api/v2/users/{accountId}/media/{uploaded-file-name} Where filename is the original filename of your uploaded media. |
message.segmentCount | int | This indicates the number of segments the original message from the user is broken into before sending over to carrier networks. Segmentation of messages depends on the size and encoding. Bandwidth will segment the message if the character count is over the below limits: - 160 for GSM-7 - 70 for UCS-2 For MMS messages the segment count will always be set to 1 |
Examples
- Inbound SMS
- Inbound Group MMS
POST /your_url HTTP/1.1
Content-Type: application/json; charset=utf-8
User-Agent: BandwidthAPI/v2
[
{
"type" : "message-received",
"time" : "2016-09-14T18:20:16Z",
"description" : "Incoming message received",
"to" : "+12345678902",
"message" : {
"id" : "14762070468292kw2fuqty55yp2b2",
"time" : "2016-09-14T18:20:16Z",
"to" : ["+12345678902"],
"from" : "+12345678901",
"text" : "Hey, check this out!",
"applicationId" : "93de2206-9669-4e07-948d-329f4b722ee2",
"media" : [
"https://messaging.bandwidth.com/api/v2/users/{accountId}/media/14762070468292kw2fuqty55yp2b2/0/bw.png"
],
"owner" : "+12345678902",
"direction" : "in",
"segmentCount" : 1
}
}
]
POST /your_url HTTP/1.1
Content-Type: application/json; charset=utf-8
User-Agent: BandwidthAPI/v2
[
{
"type" : "message-received",
"time" : "2016-09-14T18:20:16Z",
"description" : "Incoming message received",
"to" : "+12345678902",
"message" : {
"id" : "14762070468292kw2fuqty55yp2b2",
"time" : "2016-09-14T18:20:16Z",
"to" : [
"+12345678902",
"+12345678903"
],
"from" : "+12345678901",
"text" : "Hey, check this out!",
"applicationId" : "93de2206-9669-4e07-948d-329f4b722ee2",
"media" : [
"https://messaging.bandwidth.com/api/v2/users/{accountId}/media/14762070468292kw2fuqty55yp2b2/0/bw.png"
],
"owner" : "+12345678902",
"direction" : "in",
"segmentCount" : 1
}
}
]
Outbound Message Webhooks
Callbacks will be sent via an HTTP POST request to the Callback URL for the Application associated with the applicationId
field sent with the send message payload. You will get a callback for any event related to that message.
- For example, you will get an HTTP callback when your message is delivered, or blocked. In addition, you will get an event for any kind of Delivery Receipt that the destination carrier sends back, regarding the delivery of your message.
For each outbound message, you will receive either (but not both) a Message Delivered
or Message Failed
event.
- It is essential to check the direction of the message in the callback you receive. For example, if your use case depends on responding to inbound messages, you do not want to respond to an outbound message callback. This could create a loop of messages being sent from your account as you continuously respond to outbound message callbacks.
Delivery receipts are now supported for MMS & Group Messaging. During this beta phase, you will need to request this functionality to be enabled on your account. Once enabled you will need to support all three possible callback events for MMS (Message Delivered, Message Failed, & Message Queued callbacks). Visit our Support Site to learn more about enabling MMS DLR on your account.
Message Sending
You will receive this callback between when the message is received by Bandwidth and the terminal events (message delivered, message failed) for MMS only if you have the Feature_MMS_DLR
feature flag enabled.
Message Delivered
MMS and Group messages do currently support delivery receipts. However, you will need to have this enabled. Without the delivery receipts enabled, you will still receive a message delivered event when the message is sent. The message delivered event will not represent true delivery for only MMS and Group Messages. This will mean your message has been handed off to the Bandwidth's MMSC network, but has not been confirmed at the downstream carrier.
Message Failed
For MMS and Group Messages, you will only receive this callback if you have enabled delivery receipts on MMS.
Request Parameters
- Message Sending
- Message Delivered
- Message Failed
Parameter | Type | Description |
---|---|---|
type | string | The Event type |
time | array | The time of the event described in the receipt |
description | string | A detailed description of the event described by the receipt |
to | string | The destination number for an outbound message receipt |
message | Object | An object of message information |
message.id | string | The unique ID of this message |
message.owner | string | The phone number this particular message is associated with. For an outbound message, this is always the from number.For an inbound message, this will be (one of) the to number(s).For instance, if this is an inbound group message, the owner field will be set to the to number that this particular copy of the group message belongs to. |
message.time | string | The time stamp of when message was created |
message.direction | string | The direction of the message relative to Bandwidth. Will only be out for this event |
message.to | array | The phone number (or numbers) the message the message is sent to. On a POST, this can be a String, or an array of one or more numbers. In all other places, this will be an array. |
message.from | string | The phone number the message was sent from |
message.text | string | Empty text/string. Message text content will not be sent in callback. |
message.applicationId | string | The ID of the Application your from number is associated with. |
message.media | array | A list of URLs to include as media attachments as part of the message |
message.tag | string | An custom String that you can use to track this particular message |
message.segmentCount | int | This indicates the number of segments the original message from the user is broken into before sending over to carrier networks |
Parameter | Type | Description |
---|---|---|
type | string | The Event type |
time | string | The time of the event described in the receipt |
description | string | A detailed description of the event described by the receipt |
to | string | The destination number for an outbound message receipt |
message | Object | An object of message information |
message.id | string | The unique ID of this message |
message.owner | string | The phone number this particular message is associated with. For an outbound message, this is always the from number.For an inbound message, this will be (one of) the to number(s).For instance, if this is an inbound group message, the owner field will be set to the to number that this particular copy of the group message belongs to. |
message.time | string | The time stamp of when message was created |
message.direction | string | Whether the message was sent from Bandwidth, or received by a Bandwidth number |
message.to | array | The phone number (or numbers) the message the message was sent to. This will always be formatted as an array in the callback. Note: On a POST request to create a message, this can be a String comprising a single number, or an array of one or more numbers. Bandwidth will always return the message.to value as an array in |
message.from | string | The phone number the message was sent from |
message.text | string | Empty text/string. Message text content will not be sent in callback. |
message.applicationId | string | The ID of the Application your from number is associated with. |
message.media | array | A list of URLs to include as media attachments as part of the message |
message.tag | string | An custom String that you can use to track this particular message |
message.segmentCount | int | This indicates the number of segments the original message from the user is broken into before sending over to carrier networks |
Parameter | Type | Description |
---|---|---|
type | string | The Event type |
time | array | The time of the event described in the receipt |
errorCode | integer | The error code (if any). See the error docs for a detailed list |
description | string | A detailed description of the event described by the receipt |
to | string | The destination number for an outbound message receipt |
message | Object | An object of message information |
message.id | string | The unique ID of this message |
message.owner | string | The phone number this particular message is associated with. For an outbound message, this is always the from number.For an inbound message, this will be (one of) the to number(s).For instance, if this is an inbound group message, the owner field will be set to the to number that this particular copy of the group message belongs to. |
message.time | string | The time stamp of when message was created |
message.direction | string | Whether the message was sent from Bandwidth, or received by a Bandwidth number |
message.to | array | The phone number (or numbers) the message the message is sent to. On a POST, this can be a String, or an array of one or more numbers. In all other places, this will be an array. |
message.from | string | The phone number the message was sent from |
message.text | string | Empty text/string. Message text content will not be sent in callback. |
message.applicationId | string | The ID of the Application your from number is associated with. |
message.media | array | A list of URLs to include as media attachments as part of the message |
message.tag | string | An custom String that you can use to track this particular message |
message.segmentCount | int | This indicates the number of segments the original message from the user is broken into before sending over to carrier networks |
Examples
- Message Sending
- Message Delivered
- Toll Free Delivered to Handset
- MMS Delivered to Carrier
- Group MMS Delivered to Carrier
- Message Failed
POST /your_url HTTP/1.1
Content-Type: application/json; charset=utf-8
User-Agent: BandwidthAPI/v2
[
{
"time": "2020-06-25T18:42:36.979Z",
"type": "message-sending",
"to": "+15554443333",
"description": "Message is sending to carrier",
"message": {
"id": "1593110555875xo7watq5px6rbe5d",
"owner": "+15552221111",
"applicationId": "cfd4fb83-7531-4acc-b471-42d0bb76a65c",
"time": "2020-06-25T18:42:35.876Z",
"segmentCount": 1,
"direction": "out",
"to": ["+15554443333"],
"from": "+15552221111",
"text": "",
"media": ["https://dev.bandwidth.com/images/bandwidth-logo.png"],
"tag": "v2 lab"
}
}
]
POST /your_url HTTP/1.1
Content-Type: application/json; charset=utf-8
User-Agent: BandwidthAPI/v2
[
{
"type" : "message-delivered",
"time" : "2016-09-14T18:20:16Z",
"description" : "Message delivered to carrier.",
"to" : "+12345678902",
"message" : {
"id" : "14762070468292kw2fuqty55yp2b2",
"time" : "2016-09-14T18:20:16Z",
"to" : ["+12345678902"],
"from" : "+12345678901",
"text" : "",
"applicationId" : "93de2206-9669-4e07-948d-329f4b722ee2",
"owner" : "+12345678902",
"direction" : "out",
"segmentCount" : 1
}
}
]
Toll free phone numbers support "device-level" delivery receipts which indicate that the end-users device has received the message.
A timeout response with error-code: 9902 - Timed out waiting for delivery receipt. The reason a delivery receipt was not received is not known. does not indicate that the message was not received. Only that the end-users' device did not communicate back to the network indicating the message was received during the DLR timeout window.
A DLR when the from number is toll-free and the status is ok indicates that the message was indeed delivered to the end users' device.
POST /your_url HTTP/1.1
Content-Type: application/json; charset=utf-8
User-Agent: BandwidthAPI/v2
[
{
"time": "2020-03-27T15:01:22.646Z",
"type": "message-delivered",
"to": "+12345678902",
"description": "Message delivered to carrier.",
"message": {
"id": "1585321273456iprz22vjeo4tvooc",
"owner": "+18447242263",
"applicationId": "82e028a4-a852-4c65-98fc-80d18216e527",
"time": "2020-03-27T15:01:13.456Z",
"segmentCount": 1,
"direction": "out",
"to": [
"+12345678902"
],
"from": "+18447242263",
"text": "",
"tag": ""
}
}
]
POST /your_url HTTP/1.1
Content-Type: application/json; charset=utf-8
User-Agent: BandwidthAPI/v2
[
{
"type" : "message-delivered",
"time" : "2016-09-14T18:20:16Z",
"description" : "Message delivered to carrier",
"to" : "+12345678902",
"message" : {
"id" : "14762070468292kw2fuqty55yp2b2",
"time" : "2016-09-14T18:20:16Z",
"to" : ["+12345678902"],
"from" : "+12345678901",
"text" : "",
"applicationId" : "93de2206-9669-4e07-948d-329f4b722ee2",
"owner" : "+12345678902",
"direction" : "out",
"segmentCount" : 1,
"media" : ["https://dev.bandwidth.com/images/bandwidth-logo.png"]
}
}
]
You will receive a unique callback per phonenumber sent in the group message. The example below shows 1 of the 2 callbacks that would be sent from Bandwidth.
POST /your_url HTTP/1.1
Content-Type: application/json; charset=utf-8
User-Agent: BandwidthAPI/v2
[
{
"type" : "message-delivered",
"time" : "2016-09-14T18:20:16Z",
"description" : "Message delivered to carrier",
"to" : "+12345678902",
"message" : {
"id" : "14762070468292kw2fuqty55yp2b2",
"time" : "2016-09-14T18:20:16Z",
"to" : [
"+12345678902",
"+12345678903"
],
"from" : "+12345678901",
"text" : "",
"applicationId" : "93de2206-9669-4e07-948d-329f4b722ee2",
"owner" : "+12345678902",
"direction" : "out",
"segmentCount" : 1
}
}
]
POST /your_url HTTP/1.1
Content-Type: application/json; charset=utf-8
User-Agent: BandwidthAPI/v2
[
{
"type" : "message-failed",
"time" : "2016-09-14T18:20:16Z",
"description" : "forbidden to country",
"to" : "+52345678903",
"errorCode" : 4432,
"message" : {
"id" : "14762070468292kw2fuqty55yp2b2",
"time" : "2016-09-14T18:20:16Z",
"to" : [
"+12345678902",
"+52345678903"
],
"from" : "+12345678901",
"text" : "",
"applicationId" : "93de2206-9669-4e07-948d-329f4b722ee2",
"media" : [
"https://dev.bandwidth.com/images/bandwidth-logo.png"
],
"owner" : "+12345678901",
"direction" : "out",
"segmentCount" : 1
}
}
]