Skip to content
Last updated

Retrieving delivery reports with the .NET SDK

Note:

For testing purposes, we recommend you first send a message using the Getting Started Guide. Alternatively, you can test this method using the provided code sample.

Retrieve a delivery report for a batch

The Get method retrieves a delivery report by batch ID. To test it, paste the following code at the end of your Program.cs file:

var deliveryReport = await sinch.Sms.DeliveryReports.Get(new GetDeliveryReportRequest
{
    BatchId = response.Id
});

Display the result using:

Console.WriteLine(deliveryReport);

When you run it, you should see an output like the following:

{
  "Type": "delivery_report_sms",
  "BatchId": "01HJ6N9WYJ0DEJTM36T725Z2WY",
  "TotalMessageCount": 1,
  "ClientReference": null,
  "Statuses": [
    {
      "code": 401,
      "status": "Dispatched",
      "count": 1,
      "recipients": null
    }
  ]
}

The method returns a JSON response with a number of fields. Two are particularly important:

  • TotalMessageCount shows how many messages were sent.
  • Statuses gives a break down of the batch, showing how many messages belonged to a particular error code (refered to as code). 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 with the DeliveryReportType parameter:

var deliveryReport = await sinch.Sms.DeliveryReports.Get(new GetDeliveryReportRequest
{
    BatchId = response.Id,
    DeliveryReportType = DeliveryReportVerbosityType.Full
});

As you can see, Statuses now contains an extra field, recipients, a list of the phone numbers the batch was sent to.

Delivery reports can also be filtered by status and code:

var deliveryReport = await sinch.Sms.DeliveryReports.Get(new GetDeliveryReportRequest
{
    BatchId = response.Id,
    Statuses = new List<DeliveryReportStatus>
                {
                    DeliveryReportStatus.Dispatched,
                    DeliveryReportStatus.Queued,
                    DeliveryReportStatus.Delivered

                },
    Code = new List<string> { "400, 401" }
});

This example will show messages that are either delivered or in the process of being delivered. Filtering enables you to curate your delivery report analytics by only selecting a subset of the data.

See more delivery report tutorials