How can I get the delivery reports on my Webhook URL?


Follow the below-described steps to get the delivery report on your desired webhook URL:


1. Login to MSG91 panel -> Click on SMS.


MSG91 Dashboard


2. Go to the Webhook section and enter your Webhook URL in the box given and click on the Save button.


Webhook on SMS tool


3. Now our system will automatically push the delivery report to the saved URL on a real-time basis. 


4. On your Webhook URL we will push the description as well as the status of the Request ID(s). Please find below the description with the status.


Status                                      Description

1                                               Delivered

2                                               Failed

9                                               NDNC (In case of Promotional SMS only)

16 & 25                                     Rejected

17 Blocked number


#Note

1. For debugging or demo purposes you can use https://public.requestbin.com/ to have a testing callback URL.


2. The content-type for the Webhook added in the SMS section that we post is application/x-www-form-urlencoded, in case you need the content-type as application/json then you need to convert that at your end itself or you can follow the below steps in the code:


Here is a Sample Response of SMS on Webhook:


{

      "data": "[{\"senderId\":\"abcdef\",\"requestId\":\"3365646fXXXXXXXXXX\",\"report\":[{\"date\":\"2023-05-04 15:31:58\",\"number\":\"91XXXXXXX\",\"status\":\"1\",\"desc\":\"DELIVERED\"}],\"userId\":\"212212\",\"campaignName\":\"API\"}]"

}


To convert it into JSON:


var ob = {

"data": "[{\"senderId\":\"abcdef\",\"requestId\":\"3365646fXXXXXXXXXX\",\"report\":[{\"date\":\"2023-05-04 15:31:58\",\"number\":\"91XXXXXXX\",\"status\":\"1\",\"desc\":\"DELIVERED\"}],\"userId\":\"212212\",\"campaignName\":\"API\"}]"

}


var data = JSON.parse(JSON.stringify(ob))

data = JSON.parse(data.data)

console.log(data[0])

console.log(data[0].senderId)

console.log(data[0].report[0].date)



Output:


{

    senderId: 'abcdef' 

    requestId: '3365646fXXXXXXXXXX' 

    report: [

   {

     date: '2023-05-04 15:31:58', 

     number: '91XXXXXXX',

     status: '1', 

     desc: 'DELIVERED'

   }

 ], 

  userId: '212212', 

  campaignName: 'API'

}


abcdef