For testing purposes, we recommend you first send a message using the Getting Started Guide.
The get method retrieves a delivery report by batch ID. To test it, paste the following code at the end of your index.mjs file:
const requestData = {
batch_id: response.id,
};
sinchClient.sms.deliveryReports
.get(requestData)
.then((response) => console.log(response))
.catch((error) => console.error("There was an error!", error.response));When you run it, you should see an output like the following:
{
"batch_id": "01J06CY78GZ2F74YZNNH2VBWR6",
"statuses": [
{
"code": 412,
"count": 1,
"status": "Aborted"
}
],
"total_message_count": 1,
"type": "delivery_report_sms"
}The method returns a JSON object with a number of fields. Two are particularly important:
total_message_countshows how many messages were sent.statusesgives a break down of the batch.Countshows how many messages belonged to a particular error code (refered to ascode). This helps developers understand the proportion of messages that were delivered successfully versus those that failed.
The delivery report is a summary report by default, so recipients aren't shown. If you want to see the recipients, you can set the delivery report to full by adding the type to the request parameters:
const requestData = {
batch_id: response.id,
type: "full",
};
const deliveryReport = await sinchClient.sms.deliveryReports.get(requestData);Display the result using:
const prettyJSON = JSON.stringify(deliveryReport, null, 2);
console.log(prettyJSON);You should now see an output like the following:
{
"batch_id": "01H...",
"statuses": [
{
"code": 412,
"count": 1,
"recipients": [
"447..."
],
"status": "Aborted"
}
],
"total_message_count": 1,
"type": "delivery_report_sms"
}As you can see, the `recipients` field is now included in the response. It contains the phone numbers the batch was sent to.
Delivery reports can also be filtered by status and code:
const requestData = {
batch_id: response.id,
status: ['Dispatched', 'Delivered'],
code: ["400,401"]
};
const deliveryReport = await sinchClient.sms.deliveryReports.get(requestData);This filtering allows you to understand what proportion of messages were successfully delivered and drill down into causes of failure for those that were not.
- Index Page
- Retrieve a delivery report for a batch
- Retrieve a delivery report for a specific recipient
- Retrieve a list of delivery reports