Rename a group with Node.js continued

Have a group already?

If you have an existing group in mind, skip ahead to the next section.

Name a group

This part shows how to create a group and name it simultaneously. First things first, any string less than or equal to 20 characters is allowable.

To name a group of contacts, you can either do it during intial group creation or you can update the group to include a name. We have included both code samples.

The parameter we're working with for group naming is aptly called name.

Create a file

This part covers how to name a group at the time the group is created.

  1. Create a new file called nameGroup.mdx.

Name a group

import fetch from 'node-fetch';

async function run() {
  const servicePlanId = 'YOUR_service_plan_id';
  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: [
          'member_MSISDNs',
          'as_strings_in_array',
          '16051234567'
        ],
        name: 'YOUR_group_name'
      })
    }
  );

  const data = await resp.json();
  console.log(data);
}

run();
  1. Paste the code in from the "Name a group" file.
  2. Assign your values to the following parameters:
ParameterYour value
YOUR_service_plan_idThe service plan ID found on your Sinch Customer Dashboard. SMS > APIs > REST configuration
YOUR_API_tokenThe API token found on your Sinch Customer dashboard. SMS > APIs > REST configuration > Click Show to reveal your API token.
membersIn this example, descriptions are listed. You'll want to replace these with phone numbers (MSISDNs) including the country code. With or without the leading +.
nameThe name you'd like to give your group of contacts. Example: name: "Spelunking Group"
  1. Run the code
    Copy
    Copied
    node nameGroup.mjs

Response

Be sure to copy the group id if you plan on updating the name of the group in the next step.

Copy
Copied
{
"id": "XXXXX6621XXXXX119Z8PMXXXXX",
"name": "Spelunking Group",
"size": 2,
"created_at": "2022-08-24T14:15:22Z",
"modified_at": "2022-08-24T14:15:22Z",
}
Go Back
Was this page helpful?

Name a group

import fetch from 'node-fetch';

async function run() {
  const servicePlanId = 'YOUR_service_plan_id';
  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: [
          'member_MSISDNs',
          'as_strings_in_array',
          '16051234567'
        ],
        name: 'YOUR_group_name'
      })
    }
  );

  const data = await resp.json();
  console.log(data);
}

run();