Getting Started with the Voice API

This page will talk you through all of the necessary steps to get up and running with the Vonage Voice API.

Prerequisites

Create a Vonage account

To create your free Vonage account:

  1. In your browser, navigate to Dashboard.
  2. Add your company information and click Sign up. Vonage sends a PIN to your phone as a text message or automated phone call. The timeout for each verification attempt is 5 minutes. Note: you can associate a phone number with one account only. If your phone number is already associated with a Vonage account you should remove that phone number from the existing account.
  3. In Phone number verification, enter the PIN sent to you by Vonage and click Verify. You are logged into Dashboard and shown how to start developing with Vonage. This page is displayed each time you login until you have made your first successful call with Vonage APIs.

When you create your Vonage account you are given €2 free test credit and your account is set in DEMO mode. You can use our products to send messages to up to 10 destination numbers, a message stating that the account is in demo mode is added to all the SMS you send. To move out of the demo mode add credit to your account.

For very few countries Vonage cannot create an account for you automatically. This is because of payment restrictions or legal trading restrictions for a US registered company.

Create an Application

You can install the CLI with the following command:

npm install --location=global @vonage/cli

Before you can start working with your apps, you need to register your configuration: API Key and Secret. You can find them via the Dashboard, in API Settings. Once set, initialize your account using the following command:

vonage config:set --apiKey=XXXXXX --apiSecret=XXXXXX

As soon as the CLI is both installed and configured, use it to create a Vonage application using the following command:

vonage apps:create

The command starts an interactive prompt to ask for the application name, and the capabilities you want to enable - make sure to enable Voice.

When finished, it creates the vonage_app.json file in the current directory containing the Application ID, Application name and private key. It also creates a second file with the private key name app_name.key.

Rent a Number

You can rent a number using the Vonage CLI. The following command purchases an available number in the United States:

vonage numbers:search USvonage numbers:buy 15555555555 US

Specify an alternative two-character country code to purchase a number in another country.

Now that you have both an application and a number, you need to link them together.

Replace YOUR_VONAGE_NUMBER with the number you bought and APPLICATION_ID with your application id, then run the following command:

vonage apps:link APPLICATION_ID --number=YOUR_VONAGE_NUMBER

Voice Playground

In the Developer Dashboard, you can try out the Voice API interactively in the Voice Playground. Once you are signed up for a Vonage API account, you can go to Voice Playground in the Dashboard.

Making an Outbound Call

The primary way that you'll interact with the Vonage API voice platform is via the public API. To place an outbound call, you make a POST request to https://api.nexmo.com/v1/calls.

To make your first call with the Voice API, choose your language below and replace the following variables in the example code:

KeyDescription
VONAGE_NUMBERYour Vonage number that the call will be made from. For example 447700900000.
TO_NUMBERThe number you would like to call to in E.164 format. For example 447700900001.

Prerequisites

Execute the following command at your terminal prompt to create the JWT for authentication:

export JWT=$(nexmo jwt:generate $PATH_TO_PRIVATE_KEY application_id=$NEXMO_APPLICATION_ID)

Write the code

Add the following to make-an-outbound-call.sh:

curl -X POST https://api.nexmo.com/v1/calls\
  -H "Authorization: Bearer $JWT"\
  -H "Content-Type: application/json"\
  -d '{"to":[{"type": "phone","number": "'$TO_NUMBER'"}],
      "from": {"type": "phone","number": "'$VONAGE_NUMBER'"},
      "answer_url":["https://raw.githubusercontent.com/nexmo-community/ncco-examples/gh-pages/text-to-speech.json"]}'

View full source

Run your code

Save this file to your machine and run it:

bash make-an-outbound-call.sh

To make this easier, Vonage provides Server SDKs in various languages that take care of authentication and creating the correct request body for you.

What Next?

Once you've made your first call, you're ready to try out other aspects of the Voice API. Check out our documentation and references linked below for more information.

Documentation

References