STEP 1. Login to MSG91 panel -> Click on SMS.
STEP 2. Go to the Webhook section and enter your Webhook URL in the box given and click on the Save button.
STEP 3. Now our system will automatically push the delivery report to the saved URL on a real-time basis.
STEP 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/ or https://httpdump.app to have a testing callback URL.
2. The content-type for the Webhook added in the SMS section is set as application/x-www-form-urlencoded. If you require the content-type to be application/json, you will need to handle the conversion on your end. Alternatively, you can follow the steps provided below in the code:
(a) Below is an example of a sample response for an SMS request on a webhook:
{
"data": "[{\"senderId\":\"abcdef\",\"requestId\":\"3365646fXXXXXXXXXX\",\"report\":[{\"date\":\"2023-05-04 15:31:58\",\"number\":\"91XXXXXXX\",\"status\":\"1\",\"desc\":\"DELIVERED\"}],\"userId\":\"12345\",\"campaignName\":\"API\"}]"
}
To convert it into JSON:
var obj = {
"data": "[{\"senderId\":\"abcdef\",\"requestId\":\"3365646fXXXXXXXXXX\",\"report\":[{\"date\":\"2023-05-04 15:31:58\",\"number\":\"91XXXXXXX\",\"status\":\"1\",\"desc\":\"DELIVERED\"}],\"userId\":\"12345\",\"campaignName\":\"API\"}]"
}
var data = JSON.parse(JSON.stringify(obj))
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: '12345',
campaignName: 'API'
}
1. To obtain additional values in the webhook response, you have the option to include a custom parameter named "CRQID" in the API. However, please note that the "CRQID" parameter only allows alphanumeric values and does not support spaces or special characters.
It is applicable for all versions of SMS API.
Sample Payloads V5 or FLOW API:
{
"flow_id": "60b07XXXXXXXXXXXXXXX",
"sender": "TESTIN",
"recipients": [
{
"mobiles": "919999999999",
"var": "XYZ",
"CRQID": "Beta1"
},
{
"mobiles": "91888888888",
"var": "XYZ",
"CRQID": "Beta2"
}
]
}
Output:
data= [{"senderId":"TESTIN", "requestId": "33666c73574c303830353738", "report": [{"date": "2023-06-12 19:49:39", "number": "919999999999", "clientid":''12345", "CRQID": "Beta1", "status": "1", "desc" :"DELIVERED"}], "userId": "12345", "campaignName": "API"'}]
data= [{"senderId":"TESTIN", "requestId": "33666c73574c303830353738", "report": [{"date": "2023-06-12 19:49:39", "number": "91888888888", "clientid":''12345", "CRQID": "Beta2", "status": "1", "desc" :"DELIVERED"}], "userId": "12345", "campaignName": "API"'}]
2. We started showing the failure reason of any SMS request on Webhook. The sample response will look like below:
data= [{"senderId":"TESTIN","requestId":"33666d73756c393431393033","report":[{"date":"2023-06-13 19:21:13","number":"91888888888","clientid":"12345","CRQID":"Beta2","status":"2","desc":"FAILED", "failedReason":"Template Inactive on DLT"}],"userId":"12345","campaignName":"API"}]