Get started updating a subproject using Node.js

Occassionally, you may need to update the details of a subproject using the Subproject API. This guide will walk you through how to update all details of your previously created subproject.

Note:

Before you can get started, you need the following already set up:

Steps:
  1. Set up your Node.js application.
  2. Update your subproject.

Set up your Node.js application

  1. Once you setup your free Sinch account, create a new node app with npm.
    Copy
    Copied
    npm init
  2. Accept the defaults for the application.
  3. Add the fetch package with npm to generate the necessary dependencies.
    Copy
    Copied
    npm install node-fetch
  4. Create a new file named index.mjs in the project and paste the provided code into the file.

Update a subproject

import fetch from 'node-fetch';

async function run() {
  const subprojectId = 'YOUR_subprojectId_PARAMETER';
  const resp = await fetch(
    `https://subproject.api.sinch.com/v1alpha1/subprojects/${subprojectId}`,
    {
      method: 'PATCH',
      headers: {
        'Content-Type': 'application/json',
        Authorization: 'Bearer YOUR_Access_token'
      },
      body: JSON.stringify({
        "displayName": "YOUR_customer\'s_updated_displayName",
        "labels": {
            "YOUR_new_key": "YOUR_new_value2"
        }
      })
    }
  );

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

run();

Update your subproject

Now, we'll customize and run the code that will update your subproject.

Fill in your parameters

  1. Assign your values to the following parameters:
ParameterYour value
YOUR_subprojectIdThe subproject ID that you would like to update.
displayNameThe display name of the subproject is replaced by providing a new one.
labelsUpdate any label key:value pairs. You can assign new values to current keys or add entirely new pairs.
  1. Save the file.
  2. Execute the code and create your first subproject.

    Run the following command:

    Copy
    Copied
    node index.mjs

Next steps

Check out our full API reference for more subproject options.

Was this page helpful?

Update a subproject

import fetch from 'node-fetch';

async function run() {
  const subprojectId = 'YOUR_subprojectId_PARAMETER';
  const resp = await fetch(
    `https://subproject.api.sinch.com/v1alpha1/subprojects/${subprojectId}`,
    {
      method: 'PATCH',
      headers: {
        'Content-Type': 'application/json',
        Authorization: 'Bearer YOUR_Access_token'
      },
      body: JSON.stringify({
        "displayName": "YOUR_customer\'s_updated_displayName",
        "labels": {
            "YOUR_new_key": "YOUR_new_value2"
        }
      })
    }
  );

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

run();