Nexmo

Voice - Nexmo

Nexmo

Turn calls into connections with easy-to-implement voice solutions

For a better customer experience

  • Communication

API reference on SwaggerHub API reference on Postman

Introduction

Nexmo Voice is one of the main nexmo application ecosystem. It allows you to create and manage high-quality voice operation applications on the cloud.

Nexmo Voice is a HTTP-based RESTful API. All API accesses are over HTTPS combined with OAuth2.0 for extra security. Request and response bodies follows JSON format to make the exchange of information fast, easy and reliable.

Conceptual model

Conceptual model

Definitions

Conversation, leg, conference

Communication can be 1-to-1 or 1-to-n from or to the Nexmo platform. While 1-to-1 calls are known as a leg, 1-to-n calls are known as a conversation. Each call connected to a conversation is its own leg.

NCCO

A Nexmo Call Control Object (NCCO) is a JSON array that you use to control the flow of a Voice API call. For your NCCO to execute correctly, the JSON objects must be valid.

The Call event model is asynchronous. A static or dynamically created NCCO script provides the business logic for your Call. When a Call is placed to your number, Nexmo makes a synchronous request to the webhook endpoint you set as the answer_url for your number and retrieves the NCCO object that controls the Call.

Extended information regarding NCCOs can be found in our NCCO reference page.

Webhook

Method to augment or alter the behavior of your application via user-defined HTTP callbacks. In your case webhook defines the behavior of your application.

DTMF

Dual Tone Multi Frequency (DTMF), is a form of signaling used by phone systems to transmit the digits 0-9 and the * and # characters.

Text-to-Speech

Nexmo uses Text-to-speech engines to allow you to play machine generated speech in your calls. This feature can be added via NCCOs with the use of talk action or by making a put request on an in-progress call. There are 23 languages available with different styles and genders.

Recording

Nexmo Voice API offers the ability to record call audio in several ways:

SIP Trunk

To use Session Initiation Protocol (SIP), see the SIP documentation page

API workflow

API workflow

Features

  • Scales with existing web solutions
  • Easy to configure
  • Records and stores any call
  • Conference calls
  • Text-to-Speech messages in 23 languages

Getting started

The API is divided into 2 groups of resources:

  • Application: Nexmo App Management resource. Allows CRUD on applications
  • Voice: Voice call management resource. Allows CRUD on the call

You can try the application from different tools/platforms.

  • SwaggerHub
  • Postman

Authentication

OAuth 2.0

For accessing and/or manipulating the resources, the client application (your application) needs to be granted permission to do so. The OAuth 2.0 standard defines a protocol that allows such third party authorization through the use of access tokens. Access tokens are central in the protocol. These tokens, in the form of strings, are delivered by an authorization server (our authentication server) and they enable the client application to securely access protected data on behalf of the resource owner (the end user).

We use Client Credentials Grant. This means the application makes the request to the authentication service by sending authorization credentials. The service responds with an access token among other useful information.

Get access token with cURL

Copy your app's credentials and replace APP_CONSUMER_KEY and APP_CONSUMER_SECRET with the copied values, then execute below curl command to receive access token.

curl -X POST  'https://api-prd.kpn.com/oauth/client_credential/accesstoken?grant_type=client_credentials'  -H 'content-type: application/x-www-form-urlencoded'  -d 'client_id=APP_CONSUMER_KEY&client_secret=APP_CONSUMER_SECRET'

Note: If you are using cURL for Windows then please use the below command.

curl -X POST "https://api-prd.kpn.com/oauth/client_credential/accesstoken?grant_type=client_credentials" -H "content-type: application/x-www-form-urlencoded" -d "client_id=APP_CONSUMER_KEY&client_secret=APP_CONSUMER_SECRET"

The authorization service returns a JSON message that contains the access token field.

{
    "refresh_token_expires_in": "0",
    "api_product_list": "[xxxxxxx]",
    "api_product_list_json": [
        " xxxxxxx"
    ],
    "organization_name": "kpn",
    "developer_email": "demo123@kpn.com",
    "token_type": "Bearer",
    "issued_at": "1521039195424",
    "client_id": "APP_CONSUMER_KEY",
    "access_token": "haf2SDl07E9N7RluNQ4kJ1TkGgso",
    "application_name": "6e38ed2d-48b1-4362-97d6-04254065d79c",
    "scope": "",
    "expires_in": "3599",
    "refresh_count": "0",
    "status": "approved"
}

Get access token with SwaggerHub

  1. Upon loading completed within SwaggerHub, look top right for the Authorize button and click it.
  2. In the form, fill in client_id and client_secret fields, using your app's credentials.
  3. Click Authorize.
  4. Now you are authorized to issue the requests provided.

Get access token with Postman

  1. Select Get Access Token from the collection.
  2. Make sure the right Environment corresponding to the API is selected.
  3. Edit the environment variables client_id and client_secret, using your app's credentials.
  4. Check the response code and message.
  5. Press the Sendbutton to get the access token.
  6. Now you are authorized to issue the other requests in the collection.

How to...

Create the Nexmo Application

Remember the application uuid because it will be needed to make calls.

SwaggerHub:

  1. Select POST /applications
  2. Click on Try out
  3. Edit the request body by filling the name and answer_url
  4. Click on execute button
  5. Check the response code and message

Postman:

  1. Click on (POST) Create new application resource
  2. Fill the name and answer_url
  3. Click on send
  4. Check the response code and message

Create a call

SwaggerHub:

  1. Select POST /voice/calls
  2. Click on Try out
  3. Update the ApplicationID header with your application identifier
  4. Edit the request body by filling to, from and answer_url fields
  5. Click on execute button
  6. Check the response code and message

Postman:

  1. Click on (POST) Create an outbound call Update the Headers section by filling the ApplicationId field
  2. Update the body fields
  3. Click on send
  4. Check the response code and message

Return codes

Code   Description
200   Success
201   Created
202   Accepted
302   Found. Link in location header
400   Bad request
401   Unauthorized
403   Forbidden
404   Not found
405   Method not allowed
412   Precondition failed
429   Too many requests
500   Internal server error
502   Bad gateway
503   Service unavailable

API versions

Version   Description
v1   Initial version