Make an outbound call

Making outbound calls from Nexmo is easy. In this building block we'll use the Voice API to start a call and play a text-to-speech message on answer.

Prerequisites

Example

To make a test outbound voice call, sign up for an account and replace the following variables in the example below:

Key Description
NEXMO_NUMBER Your Nexmo number that the call will be made from. For example 447700900001.
TO_NUMBER The number you would like to call to in E.164 format. For example 447700900000.
NEXMO_APPLICATION_ID The ID of the application that you created.

Depending on which library you are using you will need to replace any occurrences of the following:

Key Description
NEXMO_API_KEY You can find this in your account overview
NEXMO_API_SECRET You can find this in your account overview
NEXMO_APPLICATION_PRIVATE_KEY_PATH The path to your private key file. e.g. private.key

Create a JWT for authentication using the Application ID and the Nexmo CLI:

APPLICATION_JWT="$(nexmo jwt:generate ./private.key application_id=NEXMO_APPLICATION_ID)"

Make a call:

curl -X POST https://api.nexmo.com/v1/calls\
  -H "Authorization: Bearer "$APPLICATION_JWT\
  -H "Content-Type: application/json"\
  -d '{"to":[{"type": "phone","number": TO_NUMBER}],
      "from": {"type": "phone","number": NEXMO_NUMBER},
      "answer_url":["https://developer.nexmo.com/ncco/tts.json"]}'

Prerequisites

Install the Nexmo library

Initialize the library

Code

nexmo.calls.create({
  to: [{
    type: 'phone',
    number: TO_NUMBER
  }],
  from: {
    type: 'phone',
    number: NEXMO_NUMBER
  },
  answer_url: ['https://developer.nexmo.com/ncco/tts.json']
})

Prerequisites

Install the Nexmo library

Initialize the library

Code

String NEXMO_NUMBER = envVar("NEXMO_NUMBER");
String TO_NUMBER = envVar("TO_NUMBER");
String ANSWER_URL = "https://developer.nexmo.com/ncco/tts.json";

client.getVoiceClient().createCall(
        new Call(TO_NUMBER, NEXMO_NUMBER, ANSWER_URL)
);

Prerequisites

Install the Nexmo library

Initialize the library

Code

$call = $client->calls()->create([
    'to' => [[
        'type' => 'phone',
        'number' => TO_NUMBER
    ]],
    'from' => [
        'type' => 'phone',
        'number' => NEXMO_NUMBER
    ],
    'answer_url' => ['https://developer.nexmo.com/ncco/tts.json'],
]);

Prerequisites

Install the Nexmo library

Initialize the library

Code

response = client.create_call({
  'to': [{'type': 'phone', 'number': TO_NUMBER}],
  'from': {'type': 'phone', 'number': NEXMO_NUMBER},
  'answer_url': ['https://developer.nexmo.com/ncco/tts.json']
})

pprint(response)

Prerequisites

Install the Nexmo library

Initialize the library

Code

client.calls.create(
  to: [{
    type: 'phone',
    number: TO_NUMBER
  }],
  from: {
    type: 'phone',
    number: NEXMO_NUMBER
  },
  answer_url: [
    'https://developer.nexmo.com/ncco/tts.json'
  ]
)