Create groups tutorial continued
Connect your data
Connect your own database. Because data comes in all shapes and sizes, we'll leave this step to you!
In our sample, we'll add data directly to the request body for testing.
Tip:
As you prepare your contacts data, keep in mind the members
body parameter is your user's phone number (msisdn
) and it must be in E.164 format (country code, area code, and no dashes in the phone number).
Add the code to your file
Copy and paste the "Create a group" code into your index.mjs
file.
Create a group
// Get your servicePlanId and API token
// from the Sinch Customer Dashboard:
// https://dashboard.sinch.com/sms/api/rest
import fetch from 'node-fetch';
// Import any other connections you'll need here
async function run() {
const servicePlanId = 'YOUR_servicePlanId';
const resp = await fetch(
`https://us.sms.api.sinch.com/xms/v1/${servicePlanId}/groups`,
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: 'Bearer YOUR_API_token'
},
body: JSON.stringify({
members: [
'YOUR_recipient_phone_numbers',
'including_country_code',
'16261234567',
'16469876543'
],
name: 'YOUR_group_name'
})
}
);
const data = await resp.json();
console.log(data);
}
run();
Fill in your parameters
- Assign your values to the following parameters:
Parameter | Your value |
---|---|
servicePlanId | The service plan ID found on your Sinch Customer Dashboard. SMS > APIs > REST configuration |
YOUR_API_token | The API token found on your Sinch Customer dashboard. SMS > APIs > REST configuration > Click Show to reveal your API token. |
members | Here is where you will list the phone numbers (MSISDNs) you want in the group as strings in an array. The country code must preceed the number. The intial list is limited to 10,000 numbers. |
name | The name of the group you're creating. It must be between 1-20 characters. |
- Save the file.
Run the code
- Run the following command in your terminal/command prompt to create a group:
node index.mjs
- Copy the
id
of the group, You'll need it later.
Successful Response
A successful response will look like this:
{
id: '01XXJ3HFXXT3CA0X1NGZCXXXXX',
name: 'March Signups',
created_at: '2022-04-13T18:38:59.719Z',
modified_at: '2022-04-13T18:38:59.719Z',
child_groups: []
}
Repeat!
Now following the same process, make another call to the API to create an additional group.
In the next steps, we'll turn these groups into child groups of a parent group.
Go back