Technical Details

The Vonage Voice API is the easiest way to build high-quality voice applications in the Cloud. With the Voice API you can:

  • Build apps that scale with the web technologies you are already using
  • Control the flow of inbound and outbound calls in JSON with Nexmo Call Control Objects (NCCO). (Nexmo is now Vonage).
  • Record and store inbound or outbound calls
  • Create conference calls
  • Send text-to-speech messages in 40 languages with different genders and accents

Contents

In this document you can learn about:

Getting Started

Try it now, and make your first voice call.

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 (Voice ‣ Voice Playground).

Using the API

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 this easier, Vonage provides Server SDKs in various languages that take care of authentication and creating the correct request body for you.

To get started, choose your language below and replace the following variables in the example code:

Key Description
VONAGE_NUMBER Your Vonage number that the call will be made from. For example 447700900000.
TO_NUMBER The number you would like to call to in E.164 format. For example 447700900001.

Prerequisites

A Vonage application contains the required configuration for your project. You can create an application using the Vonage CLI (see below) or via the dashboard. To learn more about applications see our Vonage concepts guide.

Install the CLI

npm install -g nexmo-cli

Create an application

Once you have the CLI installed you can use it to create a Vonage application. Run the following command and make a note of the application ID that it returns. This is the value to use in NEXMO_APPLICATION_ID in the example below. It will also create private.key in the current directory which you will need in the Initialize your dependencies step

Vonage needs to connect to your local machine to access your answer_url. We recommend using ngrok to do this. Make sure to change demo.ngrok.io in the examples below to your own ngrok URL.

nexmo app:create "Outbound Call code snippet" https://raw.githubusercontent.com/nexmo-community/ncco-examples/gh-pages/text-to-speech.json http://demo.ngrok.io/webhooks/events --keyfile private.key

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": "'$VOICE_TO_NUMBER'"}],
      "from": {"type": "phone","number": "'$VONAGE_VIRTUAL_NUMBER'"},
      "answer_url":["'"$VOICE_ANSWER_URL"'"]}'

View full source

Run your code

Save this file to your machine and run it:

bash make-an-outbound-call.sh

References

Further Reading