Skip to content
Last updated

Retrieving delivery reports with the Java SDK

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 App.java file:

DeliveryReportBatch response = client.sms().deliveryReports().get(batchId, null);

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

DeliveryReportBatchSMS{} DeliveryReportBatch{
statuses=[DeliveryReportStatusDetails{code=400,
count=1, recipients=[], status=Queued}], totalMessageCount=1}
BaseDeliveryReport{batchId='01HKD0Z7NX7ZY0GF6N2VBPA78K',
clientReference='null'}

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:

 DeliveryReportBatchGetRequestParameters parameters=DeliveryReportBatchGetRequestParameters.builder()
                .setType(DeliveryReportType.FULL)
                .build();

DeliveryReportBatch response = client.sms().deliveryReports().get(batchId, parameters);

You should now see an output like the following:

 Full Response :DeliveryReportBatchSMS{} DeliveryReportBatch{
 statuses=[DeliveryReportStatusDetails{code=401, count=1,
 recipients=[447...], status=Dispatched}], totalMessageCount=1}
 BaseDeliveryReport{batchId='01H...', clientReference='null'}

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:

 DeliveryReportBatchGetRequestParameters parameters=DeliveryReportBatchGetRequestParameters.builder()
                .setStatuses(Arrays.asList(
                        DeliveryReportStatus.from(0), DeliveryReportStatus.QUEUED, DeliveryReportStatus.DISPATCHED, DeliveryReportStatus.DELIVERED))
                .setCodes(Arrays.asList("400, 401"))
                .build();

DeliveryReportBatch response = client.sms().deliveryReports().get(batchId, parameters);

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.

See more delivery report tutorials