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

Before you begin, you will need the following:

Create a Vonage account

To work with our APIs, you will need to sign up for an account. This will give you an API key and secret that you can use to access our APIs.

You can use the Voice API to make a voice call. Use the test number 123456789 as the caller ID, and call the number you originally provided during sign-up. Please note that this feature is only available for demo or trial accounts until you add credit to your account.

Try the Voice API

After signing up for a Vonage API account, access the Developer Dashboard and go to the Make a Voice Call section. Here, you can make a test call to see the Voice API in action.

Try Voice API Developer Dashboard view

Let’s now learn how to use the Voice API in your application.

Create an Application

Go to the Application's page on the Dashboard, and define a Name for your Application.

An example of brand new application

Make sure to click on the Generate public and private key button, and keep the file private.key around.

Then, enable the Voice capability. For the moment, leave everything by default.

An example of enabling Voice capabilities

Finally, click Generate new application at the bottom of the page.

Rent a Number

To rent a number, you must first add credit to your account.

You can skip this step if you want to use the test number 123456789 as a caller ID, and call the number you originally provided during sign-up.

In the Dashboard, go to the Buy Numbers page. Make sure to tick Voice in the search filter, and select the country you want to buy a number in. In some countries, you may need to request a number, as additional documents may be required.

An example of number research

You can then click the Buy button next to the number you want, and validate your purchase.

Congratulations! Your virtual number is now listed in Your Numbers.

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:

Key Description
VONAGE_NUMBER Your Vonage number that the call will be made from. For example 447700900000. If you skipped the Rent a Number step, use the test number “123456789”.
TO_NUMBER The number you would like to call to in E.164 format. For example 447700900001. If you skipped the Rent a Number step, use the number you originally provided during sign-up.

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": "'$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

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. We recommend starting with the Technical Details page for a comprehensive overview of the Vonage Voice API. To understand various call flows, check out the Call Flow guide. If you're interested in building a basic Voice Notification application, refer to the Voice Notifications How-to guide. For more information, please refer to our Voice API documentation.