Assigning a name to a batch can be done in the /batches
endpoint. The main parameter we're looking at is client_reference
for naming batches.
If you're looking to set your own ID for a batch, you're in the right place.
Copy and paste the "Name your batch" code into your nameBatch.mjs
file.
Name your batch
// 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_number';
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: 'Testing. Testing. Is this thing on?',
type: 'mt_text',
client_reference: 'YOUR_own_ID_or_batch_name'
})
}
);
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. |
client_reference | Here is where you'll set your own batch ID or name. It can be anything you want, so long as it's a string. Any identifier you'd like to provide will work. It will show in the delivery report/callback of this batch. The limitation is 2048 characters. |
- Save the file.
- Run the following command in your terminal/command prompt to create a group:
node nameBatch.mjs
A successful response will look like this:
{
"id": "XXXXX6621VXXXXX19Z8PMXXXXX",
"to": [
15551231234,
15551256344
],
"from": 15551231234,
"canceled": false,
"body": "Testing. Testing. Is this thing on?",
"type": "mt_text",
"created_at": "2022-08-24T14:15:22Z",
"modified_at": "2022-08-24T14:15:22Z",
"delivery_report": "full",
"send_at": "2022-08-24T14:15:22Z",
"expire_at": "2022-08-26T14:15:22Z",
"callback_url": "http://my.url.com",
"client_reference": "YOUR_ID_or_name_shows_here",
}
You've named your batch using the client_reference
parameter. Kneadless to say, this batch is baked. Great job!
Learn how to search a list of delivery reports for your named batch
Find other useful code samples in our API reference.
Check out another tutorial.