There are two endpoints we'll put into play to integrate delivery feedback:
First, we'll prepare a batch for delivery feedback by enabling it in our
/batches
POST Send request.Then, we'll send another POST request to
/delivery_feedback
using the batch ID.
The parameter we are concerned with for this first step is feeback_enabled
in the POST Send request for the /batches
endpoint.
By setting feedback_enabled
to true
we are telling the API that we would like to allow feedback on this particular batch to be sent back to Sinch for routing optimization.
Copy and paste the "Set delivery feedback to true" code into a new file called allowDelivery.mjs
.
// Find your Service Plan ID and API Token at dashboard.sinch.com/sms/api/rest
// Find your Sinch virtual numbers at dashboard.sinch.com/numbers/your-numbers/numbers
const SERVICE_PLAN_ID = 'YOUR_service_plan_id';
const API_TOKEN = 'YOUR_API_token';
const SINCH_NUMBER = 'YOUR_Sinch_virtual_number';
const TO_NUMBER = 'recipient_numbers';
import fetch from 'node-fetch';
async function run() {
const resp = await fetch(
'https://us.sms.api.sinch.com/xms/v1/' + SERVICE_PLAN_ID + '/batches',
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: 'Bearer ' + API_TOKEN
},
body: JSON.stringify({
from: SINCH_NUMBER,
to: [
TO_NUMBER
],
body: 'Only the best route for this message.',
type: 'mt_text',
feedback_enabled: 'true',
delivery_report: 'full'
})
}
);
const data = await resp.json();
console.log(data);
}
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. |
SINCH_NUMBER | A free test number or any Sinch virtual number you've rented. Find the number on your Sinch Build Dashboard by clicking the service plan ID link and scrolling to the bottom of the page. |
TO_NUMBER | Your receipient number(s). The phone number(s) to which you want to send the test SMS message. Even if you only send to one number, it is inside an array. |
feedback_enabled | Here is where you'll set the feedback status to true . This parameter is a boolean value and by default it is set to false . |
- Save the file.
- Run the following command in your terminal/command prompt to create a group:
node allowDelivery.mjs
- Copy the batch ID value in the response.
A successful response will look like this:
{
id: '01000008YAZ00000TMJ000005W',
to: [ '12065551234' ],
from: '12065555678',
canceled: false,
body: 'Only the best route for this message.',
type: 'mt_text',
created_at: '2022-08-03T20:15:49.706Z',
modified_at: '2022-08-03T20:15:49.706Z',
delivery_report: 'full',
expire_at: '2022-08-06T20:15:49.706Z',
feedback_enabled: true,
flash_message: false
}
Once the user has received a message on their device and you have received a successful reponse, you've now given permission to send delivery feedback for this batch to Sinch for optimal message routing.
Let's go one step further and configure your batch to send feedback.