Rename a group with Node.js continued

Update a group name

Say the group has evolved and needs a better name to describe it. Let's give your group of contacts a different name.

  1. To update the name of the group, create an additional file in the project called updateGroup.mdx.

Update a group name

import fetch from 'node-fetch';

async function run() {
  const servicePlanId = 'YOUR_service_plan_id';
  const groupId = 'YOUR_group_id';
  const resp = await fetch(
    `https://us.sms.api.sinch.com/xms/v1/${servicePlanId}/groups/${groupId}`,
    {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        Authorization: 'Bearer YOUR_API_token'
      },
      body: JSON.stringify({name: 'YOUR_new_group_name'})
    }
  );

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

run();
  1. Paste the code in the "Update a group name" sample.
  2. Fill in the name parameter with the new name of your group.
Note:

Notice that we are using a different endpoint to update the group. For more update options, see our various code samples in the API reference.

Run the code

  1. Run the following command in your terminal/command prompt to create a group:
    Copy
    Copied
    node updateGroup.mjs

Successful Response

A successful response shows the new name of the group.

Copy
Copied
{
  "id": "XXXXX6621VHXXXXX9Z8PMXXXXX",
  "name": "Jazzercise 1",
  "size": 2,
  "created_at": "2022-08-24T14:15:22Z",
  "modified_at": "2022-08-24T14:15:22Z",
}

You're an all-star classifier!

Go back

Next steps

Was this page helpful?

Update a group name

import fetch from 'node-fetch';

async function run() {
  const servicePlanId = 'YOUR_service_plan_id';
  const groupId = 'YOUR_group_id';
  const resp = await fetch(
    `https://us.sms.api.sinch.com/xms/v1/${servicePlanId}/groups/${groupId}`,
    {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        Authorization: 'Bearer YOUR_API_token'
      },
      body: JSON.stringify({name: 'YOUR_new_group_name'})
    }
  );

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

run();