Configure your prerequisites

There are a few prerequisites that you need to complete before you can work through this tutorial. If you've already completed any of them, feel free to skip that step.

You can create a Vonage account via the Dashboard.

Within the Dashboard you can create Applications and purchase Vonage numbers. You can also perform these tasks using the Vonage CLI.

Install latest version of Vonage Command Line Interface (CLI)

The Vonage CLI allows you to carry out many operations on the command line. Examples include creating applications, purchasing numbers, and linking a number to an application.

To install the CLI with NPM run:

npm install -g @vonage/cli

Set up the Vonage CLI to use your Vonage API Key and API Secret. You can get these from the settings page in the Dashboard.

Run the following command in a terminal, while replacing API_KEY and API_SECRET with your own:

vonage config:set --apiKey=API_KEY --apiSecret=API_SECRET

There are two methods for creating a Voice application:

  1. Using the Vonage CLI
  2. Using the Dashboard

Each of these methods is described in the following sections.

How to create a Voice application using the Vonage CLI

To create your application using the Vonage CLI, enter the following command into the shell replacing NGROK_HOST_NAME with the ngrok host that you got when you set up ngrok:

vonage apps:create "AspNetTestApp" --voice_answer_url=http://NGROK_HOST_NAME/webhooks/answer --voice_event_url=http://NGROK_HOST_NAME/webhooks/events

This command creates a Vonage Application with Voice capability. It configures the Application with your answer and event webhook URLs and generates a private key file private.key, which you should save in your project directory.

The command returns a unique Application ID. Use this Application ID to link your Vonage virtual number to your Application by executing the following:

vonage apps:link APPLICATION_ID --number=VONAGE_NUMBER

This will link that Vonage Virtual Number to your application, which will cause all voice events occurring for that number to be routed to your designated URLs.

How to create a Voice application using the Dashboard

You can create Voice applications in the Dashboard.

To create your application using the Dashboard:

  1. Under Applications in the Dashboard, click the Create a new application button.

  2. Under Name, enter the Application name. Choose a name for ease of future reference.

  3. Click the button Generate public and private key. This will create a public/private key pair and the private key will be downloaded by your browser. Save the private key that was generated.

  4. Under Capabilities select the Voice button.

  5. In the Answer URL box, enter the URL for your inbound calls webhook, for example,

  6. In the Event URL box, enter the URL for your call status webhook, for example,

  7. Click the Generate new application button.

  8. You are now taken to the next step of the Create Application procedure where you should link your Vonage number to the application.

You have now created your application.

NOTE: Before testing your application ensure that your webhooks are configured and your webhook server is running.

Buy a Vonage number

Using the Dashboard

First you can browse your existing numbers.

If you have no spare numbers you can buy one.

Using the Vonage CLI

You can purchase a number using the Vonage CLI. The following command purchases an available number in the US. Specify an alternate two-character country code to purchase a number in another country.

$ vonage numbers:search US
$ vonage numbers:buy 15555555555 US

Link a Vonage number

Using the Dashboard

  1. Find your application in the Dashboard.
  2. Click on the application in the Your Applications list. Then click on the Numbers tab.
  3. Click the Link button to link a Vonage number with that application.

Using the Vonage CLI

Once you have a suitable number you can link it with your Vonage application. Replace YOUR_VONAGE_NUMBER with newly generated number, replace APPLICATION_ID with your application id and run this command:

vonage apps:link APPLICATION_ID --number=YOUR_VONAGE_NUMBER

You must make your webhook accessible to Vonage’s APIs over the public Internet. A straightforward way to achieve this during development without standing up your own server is to use Ngrok. To learn more, read our documentation on Ngrok.

Download and install ngrok, then execute the following command to expose your application on port 3000 to the public Internet:

./ngrok http 3000

If you are a paid subscriber you could type:

./ngrok http 3000 -subdomain=your_domain

NOTE: In this example Ngrok will divert the Vonage webhooks you specified when you created your Vonage application to localhost:3000. Although port 3000 is shown here, you can use any free port that is convenient.