Vonage Voice API - Call Authentication

See this guide for official Vonage Voice integration.

Pre-requisites

  1. First Orion Branded Communications agreement
  2. Access to First Orion Customer Portal
  3. Vetted and Approved Business
  4. Ability to originate phone calls from configured phone numbers in calling platform
  5. Understanding of current calling platform and environment to integrate required API

Generate First Orion API Keys

See the API Credentials Page for more information. API Credential Page

  1. Sign into First Orion's Customer Portal
  2. Navigate to the API Keys section on the left-hand side
  3. Click Generate Key
  4. Copy and save or download the generated keys

Examples

Python example

Libraries needed - json, requests, os

  1. Replace lines 13 and 14 with the Business API keys.
  2. Replace lines 26 and 27 with the caller and callee information.
  3. Replace line 53 with callee information.
  4. Replace line 62 with your Vonage JWT.

JavaScript Example

Libraries needed - axios

  1. Replace lines 14 and 15 with the Business API keys.
  2. Replace lines 35 and 36 with the caller and callee information.
  3. Replace line 65 with callee information.
  4. Replace line 77 with your Vonage JWT.
# CallAuth.py

import json
import requests
import os
    
def get_token():
    url = "https://api.firstorion.com/v1/auth"
    
    headers = {
      'X-SERVICE': 'auth',
      'content-type': 'application/json',
      'X-API-KEY': 'your-api-key',
      'X-SECRET-KEY': 'your-secret-key'
    }
    
    response = requests.request("POST", url, headers=headers)
    data = response.json()
    return data['token']

    
def push_precall(token):
    url = "https://api.firstorion.com/exchange/v1/calls/push"
    
    payload = json.dumps({
      "aNumber": "+15555555555",
      "bNumber": "+14155550100"
    })
    headers = {
      'Authorization': token,
      'Content-Type': 'application/json'
    }
    
    response = requests.request("POST", url, headers=headers, data=payload)
    data = response.json()
    
    value = {
        'statusCode': response.status_code,
        'body': data['body']['message']
    }
    
    # Return JSON Object
    return json.loads(json.dumps(value))


# Set payload information and authorization credentials
# Read more at https://developer.vonage.com/en/api/voice#createCall
def createCall():
    url = "https://api.nexmo.com/v1/calls/"
    
    payload = json.dumps({
       "to": [
          {
             "type": "phone",
             "number": "14155550100"
          }
       ],
       "answer_url": [
          "https://example.com/answer"
       ]
    })
    
    headers = {
      'Authorization': 'Bearer <Vonage JWT>',
      'Content-Type': 'application/json'
    }
    
    response = requests.request("POST", url, headers=headers, data=payload)
    data = response.json()
    
    # Return JSON Object
    return data
    
# Makes the pre-call push.
token = get_token()
precall = push_precall(token)
vonageCall = createCall()
print("Call Auth Info: " + precall)
print("Twilio Call Info: "+ vonageCall)
// CallAuth.js

// Libraries
const axios = require('axios'); // Install with,  npm install axios

// Gets First Orion Auth Token
const getToken = async () => {
  
    try {
      const response = await axios.post(
        'https://api.firstorion.com/v1/auth',
        null,
        {
          headers: {
            'X-SERVICE':'auth',
            'X-API-KEY': 'your-api-key',
            'X-SECRET-KEY': 'your-secret-key',
            'Content-Type': 'application/json'
          }
        }
      );
      return response.data.token;
      
    } catch (error) {
      console.error('Error:', error);
      return {
        statusCode: error.response ? error.response.status : 500,
        body: JSON.stringify({ error: error.message })
      };
    }
}

// Create Call Authentication push to First Orion for Call Authentication
// Find out more at: https://developer.firstorion.com/firstorion-public/reference/callauthentication
const push_callauth = async (token) => {
    let data = JSON.stringify({
        "aNumber": '+15555555555',
        "bNumber": '+14155550100'
    });

    let config = {
        method: 'post',
        url: 'https://api.firstorion.com/exchange/v1/calls/push',
        headers: { 
            'Authorization': token, 
            'Content-Type': 'application/json'
        },
        data : data
    };

    axios.request(config)
    .then((response) => {
        console.log(JSON.stringify(response.data));
    })
    .catch((error) => {
        console.log(error);
    });
}

// Set payload information and authorization credentials
// Read more at https://developer.vonage.com/en/api/voice#createCall
const createCall = async () => {
    let data = JSON.stringify({
       "to": [
          {
             "type": "phone",
             "number": "14155550100"
          }
       ],
       "answer_url": [
          "https://example.com/answer"
       ]
    });

    let config = {
        method: 'post',
        url: 'https://api.nexmo.com/v1/calls/',
        headers: { 
            'Authorization': 'Bearer <Vonage JWT>', 
            'Content-Type': 'application/json'
        },
        data : data
    };

    axios.request(config)
    .then((response) => {
        console.log(JSON.stringify(response.data));
    })
    .catch((error) => {
        console.log(error);
    });
}

  
// Main function to invoke the Call Authentication push for Call Authentication.
const main = async () => {
    const token = await getToken();
    const push_callauth = await push_callauth(token);
		const vonageCall = await createCall()
    console.log("Call Auth Info: " + push_callauth)
		console.log("Vonage Call Info: " + vonageCall)
}

main()

Responses

Example responses from API.

fouser@FO-user-pc Python % python3 CallAuth.py
Call Auth Info:
{
  "body": {
    "message": "Ok"
  }
}
Vonage Call Info:
{
   "uuid": "63f61863-4a51-4f6b-86e1-46edebcf9356",
   "status": "completed",
   "direction": "outbound",
   "conversation_uuid": "CON-f972836a-550f-45fa-956c-12a2ab5b7d22"
}