Make a call with Node.js

You can quickly see how the Voice API works by calling yourself using the API.

In this guide you will learn how to:

Learn how to:
  1. Sign up for your free Sinch account
  2. Buy a number
  3. Set up your Node.js application
  4. Call your phone number

What you need to know before you start

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

  • An application configured in the dashboard. Additionally, take note of the application's key and secret, as you'll need them later.
  • Node.js and a familiarity with how to create a new app.

Sign up for your free account

Already have an account?

If you already have a free account, skip to the next section

You can sign up for a free Sinch account here.

  • When you sign up, you'll have to verify your email address and phone number. This lets Sinch verify your identity and you'll also be able to use your phone to send and receive test messages.
  • After you've verified your number, you'll be prompted to create your first application.
  • After you finish setting up your account, you'll have access to your dashboard where you can view all of your applications. You can also access your account ID, set up API tokens, get phone numbers, and more.

Buy a number

Already have an number?

If you already have sinch number, skip to the next section

You can rent numbers that are set up for SMS or Voice. You can rent a number from any country where Sinch has numbers in inventory.

You can search for and purchase virtual numbers by logging in to your dashboard.

  • Go to Numbers | Rent Numbers. Available area codes with numbers to rent are displayed in the list. You can filter the area codes using the filter bars at the top of the list.

  • When you see an area code with a number of the type you want to rent, enter the number of units you want to rent in the field provided and click the Checkout button. After you checkout, you are ready to use your number and assign it to your application.

Set up your Node.js application

Create a new node app with npm.

npm init

Accept the defaults for the application.

Add the fetch package with npm to generate the necessary dependencies.

npm install fetch

Create your file

Create a new file named index.js in the project and paste the provided "Make a phone call" code into the file.

Make a phone call

// Find your application key and secret at portal.sinch.com/#/apps
// Find your Sinch numbers at portal.sinch.com/#/numbers
const applicationKey = "";
const applicationSecret = "";
const sinchNumber = "";
const locale = "";
const toNumber = "";

const basicAuthentication = applicationKey + ":" + applicationSecret;

const fetch = require('node-fetch');
const ttsBody = {
  method: 'ttsCallout',
  ttsCallout: {
    cli: sinchNumber,
    destination: {
      type: 'number',
      endpoint: toNumber
    },
    locale: locale,
    text: 'This is a call from sinch',
  }
};

fetch("https://calling.api.sinch.com/calling/v1/callouts", {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      Authorization: 'Basic ' + Buffer.from(basicAuthentication).toString('base64')
    },
    body: JSON.stringify(ttsBody)
  }).then(res => res.json()).then(json => console.log(json));

Fill in your parameters

Assign your values to the following parameters:

ParameterYour value
applicationKeyThe key found on your Sinch dashboard.
applicationSecretThe secret found on your Sinch dashboard.
sinchNumberAny inbound number you've assigned to your application. Find the number on your Sinch dashboard by clicking on your app, navigating to the Voice and Video tab, and looking in the Inbound Numbers section.
localeThe language and locale you want to use for the text-to-speech call. Locale is specified with a language code according to ISO 639, a dash and a country code according to ISO 3166-1 alpha-2. For example, American English is represented by en-US.
toNumberThe phone number that you want to call.

Save the file.

Call your phone number

Now you can execute the code and make your text-to-speech call. Run the following command:

node index.js

You should receive a phone call to the number you called with the message "This is a phone call from Sinch."

Next steps

The code you used in the index.js file sends a POST request to the Sinch API /callouts endpoint to make the call. Click here to read more about the batches endpoint.

Make a phone call

// Find your application key and secret at portal.sinch.com/#/apps
// Find your Sinch numbers at portal.sinch.com/#/numbers
const applicationKey = "";
const applicationSecret = "";
const sinchNumber = "";
const locale = "";
const toNumber = "";

const basicAuthentication = applicationKey + ":" + applicationSecret;

const fetch = require('node-fetch');
const ttsBody = {
  method: 'ttsCallout',
  ttsCallout: {
    cli: sinchNumber,
    destination: {
      type: 'number',
      endpoint: toNumber
    },
    locale: locale,
    text: 'This is a call from sinch',
  }
};

fetch("https://calling.api.sinch.com/calling/v1/callouts", {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      Authorization: 'Basic ' + Buffer.from(basicAuthentication).toString('base64')
    },
    body: JSON.stringify(ttsBody)
  }).then(res => res.json()).then(json => console.log(json));