Now, we'll configure the batch for delivery feedback. At a minimum, you'll need the service_plan_id
and batch_id
.
You can further specify if you'd like only certain phone numbers tracked by listing them under recipients
.
Copy and paste the "Send delivery feedback for a message" code into a new file called sendFeedback.mjs
.
Send delivery feedback for a message
// Find your Service Plan ID and API Token at dashboard.sinch.com/sms/api/rest
// your Batch ID is found in your previous call to the /batches endpoint.
const SERVICE_PLAN_ID = 'YOUR_service_plan_id';
const API_TOKEN = 'YOUR_API_token';
const BATCH_ID = 'YOUR_batch_id';
import fetch from 'node-fetch';
async function run() {
const resp = await fetch(
`https://us.sms.api.sinch.com/xms/v1/${SERVICE_PLAN_ID}/batches/${BATCH_ID}/delivery_feedback`,
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: 'Bearer ' + API_TOKEN
},
body: JSON.stringify ({
recipients:[
'YOUR_recipients_phone_numbers',
'+12025551234'
]
})
}
);
}
run();
- Assign your values to the following parameters:
Parameter | Your value |
---|---|
SERVICE_PLAN_ID | The service plan ID found on your Sinch Build Dashboard. SMS > APIs > REST configuration. |
API_TOKEN | The API token found on your Sinch Build Dashboard. SMS > APIs > REST configuration > Click Show to reveal your API token. |
BATCH_ID | The batch ID is provided in the response of your previous call to send a batch. Copy the value and paste it in this call to the /delivery_feedback endpoint. |
recipients | Here you'll provide the phone numbers (MSISDNs) for the recipients on whom you'd like to send feedback. These are sent as an array of strings. At least one recipient is requried for proper functionality of this endpoint. |
- Save the file.
- Run the following command to send feedback for your batch:
node sendFeedback.mjs
A successful response will be an empty 202 response.
That's it! You've configured this batch to send delivery feedback to Sinch for optimal message routing.
- Find other useful code samples in our API reference.
- Check out another tutorial.