You can read the A2P message store using a batch id to fetch the report for a particular batch. However, you have to save the batch id somewhere in your database after sending a batch (right now we don't have yet an API for querying history batches). You can see the error code of each message which failed. However, if a failure is not identified, the errorCode will be omitted. We are still improving the error list and will add more error codes and detect more failure situations.
/restapi/v1.0/account/~/a2p-sms/messages?batchId=batchId
// Response
{
"records": [
{
"id": "52511",
"from": "+16505550100",
"to":["+1650111222],
"createdAt": "2020-10-14T21:47:51.436491Z",
"lastUpdatedAt": "2020-10-14T21:47:53.032416Z",
"messageStatus": "Delivered",
"cost": 0.007,
"segmentCount": 1
},
{
"id": "52494",
"from": "+16505550100",
"to":["+1650222333],
"createdAt": "2020-10-14T20:21:23.979729Z",
"lastUpdatedAt": "2020-10-14T20:21:25.254851Z",
"messageStatus": "Delivered",
"cost": 0.007,
"segmentCount": 1
},
{
"id": "52485",
"from": "+16505550100",
"to":["+1650333444],
"createdAt": "2020-10-14T20:19:56.505461Z",
"lastUpdatedAt": "2020-10-14T22:20:01.728022Z",
"messageStatus": "DeliveryFailed",
"errorCode": "SMS-CAR-104",
"cost": 0.007,
"segmentCount": 1
},
{
"id": "52484",
"from": "+16505550100",
"to":q"+1650444555],
"createdAt": "2020-10-14T20:19:18.415601Z",
"lastUpdatedAt": "2020-10-14T20:19:18.668841Z",
"messageStatus": "SendingFailed"
}
],
"paging": {
"pageToken": "pgt1",
"perPage": 3,
"firstPageToken": "fpgt1",
"previousPageToken": "lpgt1",
"nextPageToken": "npgt1"
}
}
As you can see, some message failed in sending but does not have the error code in the response. This is because we have not implemented to return error for invalid recipient's number yet. We will improve that in the next releases.