Get started creating a subproject using Node.js

This guide will walk you through creating a new subproject for a Sinch project using Node.js.

Note:

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

Steps:
  1. Set up your Node.js application.
  2. Create 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.

Create a subproject with a display name and labels

import fetch from 'node-fetch';

async function run() {
  const parentProjectId = 'YOUR_projectId';
  const resp = await fetch(
    `https://subproject.api.sinch.com/v1alpha1/projects/${parentProjectId}/subprojects`,
    {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json', 
        Authorization: 'Bearer YOUR_Access_token'
      },
    body: JSON.stringify({
        "displayName": "Fantastic Client 1",
        "labels": {
            "YOUR-key": "YOUR_value",
            "region": "US-Northwest", 
            "populate-with": "your-metadata"         
        }
      })
    }
  );

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

run();

Create your subproject

Now, we'll customize and run the code that will create a subproject under your specified Sinch project ID.

Fill in your parameters

  1. Assign your values to the following parameters:
    ParameterYour value
    YOUR_projectIdThe corresponding project ID that you would like to create a subproject under. Your projectId can be found in the Sinch Customer Dashboard under Settings, then Access Keys.
    displayNameThe display name is a name given to represent this particular subproject. In a resale setting, this would be your customer's business name.
    labelsLabels contain a series of key:value pairs that are completely customizable. You can assign your own key and value. This is a great way to keep metadata with the subproject.
  2. Save the file.
  3. 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?

Create a subproject with a display name and labels

import fetch from 'node-fetch';

async function run() {
  const parentProjectId = 'YOUR_projectId';
  const resp = await fetch(
    `https://subproject.api.sinch.com/v1alpha1/projects/${parentProjectId}/subprojects`,
    {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json', 
        Authorization: 'Bearer YOUR_Access_token'
      },
    body: JSON.stringify({
        "displayName": "Fantastic Client 1",
        "labels": {
            "YOUR-key": "YOUR_value",
            "region": "US-Northwest", 
            "populate-with": "your-metadata"         
        }
      })
    }
  );

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

run();