API Documentation

Introduction

The Fonenode API allows developers build call solutions via a simple REST API. The API endpoint is https://api.fonenode.com/v1/.

Check out the Fonenode github repository: github.com/fonenode for code samples and client libraries. Kindly send in questions, feature request, suggestions or issues to hello@fonenode.com

HTTP methods

The API uses the HTTP methods POST, GET, PUT and DELETE. POST is generally used for resource creation, GET for retrieving data, PUT for update and DELETE for removal operations. If you are using a client that does not support PUT and DELETE methods, there are two alternatives you can use:

  1. Use POST with the additional header X-HTTP-Method-Override
  2. Pass the required method via the GET parameter: _method
    e.g: https://api.fonenode.com/v1/responses/525e3fb3b218980d35000001?_method=delete

Response Code and format

Results are returned as json. If a request is successful, a 200 status code will be returned. If the request is one that creates, a 201 is returned instead. Status codes returned for errors are described in errors.

{"id": "525e3fb3b218980d35000001"}

Authentication

All API methods require authentication. Authentication is done via HTTP basic over HTTPS. Use your auth_id and auth_secret (available in your user dashboard) as the username and password respectively.

You can also use the format https://{auth_id}:{auth_secret}@api.fonenode.com/v1/[method] to test directly from your browser.

  • CURL
    curl https://api.fonenode.com/v1/responses
    \-u auth_id:auth_secret
    \-d "text=Hello Bae"
  • PHP
    $data = array('text' => 'Hello Bae');
    $handle = curl_init();
    curl_setopt($handle, CURLOPT_URL, 'https://api.fonenode.com/v1/responses');
    curl_setopt($handle, CURLOPT_USERPWD, 'auth_id:auth_secret');
    curl_setopt($handle, CURLOPT_POSTFIELDS, $data);
    curl_setopt($handle, CURLOPT_CAINFO, dirname(__FILE__).'/cert_bundle.crt');
    curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, 1);
    curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1);
    $result = curl_exec($handle);
    $statusCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
    curl_close($handle);
    
    //echo $statusCode;
    echo '<pre>';
    print_r(json_decode($result, true));
    echo '</pre>';
  • Node.JS
    var request = require('request'); // using the request library
    request.post({
        url: 'https://api.fonenode.com/v1/responses',
        auth: {username: 'auth_id', password: 'auth_secret'},
        form: {text: 'Hello Bae'}
      }, function(err, response, body) {
        if (err)
          return console.log(err);
    
        console.log(body);
      });
    						

Errors

The API returns standard HTTP status codes when things go wrong. An additional error description will also be returned.

A 4xx means you have done something wrong - wrong authentication details (401), missing parameter (400), etc.

A 5xx means the fault is ours - a database or server error.

Status Code: 400

{
  "error": "Missing id parameter."
}

Resources

Responses

The Response resource is the backbone of the call API. It lets you create and manage reusable call interactions. This can be a simple text to be read to the caller or receiver. You can also enable options to collect feedback in form of digits from the user. (If you will be collecting input from user or building an IVR solution of some sort, we recommend you use the IVR resource instead).

1. Create A Response

Create a response you can later attach to a call or number.

URL: https://api.fonenode.com/v1/responses

Method: POST

Parameters:

  • text: Text to be read out or URL of an mp3 file to be played. (An mp3 URL should only contain numbers, alphabets, hyphens, underscores and dot)

  • voice: Optional. Response voice. woman or man. Defaults to woman.

  • retries: Optional. Number of times to read text. Defaults to 1.

  • get_digits: Optional. Set to true to accept input from user. Useful for poll applications.

  • timeout: Optional. If get_digits is true, this is the time in seconds to wait to receive the first digit.

  • no_input: Optional. Text to be read or URL of an mp3 to be played if get_digits is true and no input is received from the user.

  • no_of_digits: Optional. If get_digits is true, this is the number of digits expected from the user.

  • choices: If get_digits is true, these are the expected input from the user. It is an array element containing the required digit, label (for report purpose) and text (to be read if selected. This can also be an mp3 url). The label and text values are optional. See code sample.

  • callback_url: Optional. If get_digits is true and choices is supplied, call details and user input will be sent to this URL via POST.
    Sent parameters are:

    • call_id: ID of the call
    • response_id: Response id attached to call
    • from: Call source
    • to: Number called
    • digits: User input
    • date: Current timestamp

    If get_digits and choices parameter are not specified, only to and from will be sent to the specified url.

  • wrong_choice_response: Optional. Text to be read if get_digits is true, and the user makes a wrong input.

  • final_response: Optional. Text to be read after user has made an input.

 

Sample Code:

  • Curl
    POST https://api.fonenode.com/v1/responses
    
    $ curl https://api.fonenode.com/v1/responses \
      -u auth_id:auth_secret \
      -d "text=Which is your favorite football team? Press one for Manchester United. Two for Chelsea. Three for Arsenal. Four for Liverpool." \
      -d retries=3 \
      -d "no_input=You did not make a selection" \
      -d get_digits=true \
      -d choices[0][digit]=1 \
      -d "choices[0][label]=Manchester United" \
      -d "choices[0][text]=You selected Man United. Great!" \
      -d choices[1][digit]=2 \
      -d "choices[1][label]=You selected Chealsea. Wow!" \
      -d "choices[1][text]=Chealsea" \
      -d choices[2][digit]=3 \
      -d "choices[2][label]=Arsenal" \
      -d "choices[2][text]=You selected Arsenal. Up gunners!" \
      -d choices[3][digit]=4 \
      -d "choices[3][label]=Liverpool" \
      -d "choices[3][text]=You selected Liverpool. Beautiful!" \
      -d "wrong_choice_response=Sorry, you have made a wrong selection."
    
    Sample response (201 header code):
    
    {"id": "167e3d8d95699af944000001"}
  • PHP
    $data = array(
          'text' => 'Which is your favorite football team? Press one for Manchester United. Two for Chelsea. Three for Arsenal. Four for Liverpool.',
          'no_inputs' => 'You did not make a selection',
          'get_digits' => 'true',
          'wrong_choice_response' => 'Sorry, you have made a wrong selection.'
        );
    $handle = curl_init();
    curl_setopt($handle, CURLOPT_URL, 'https://api.fonenode.com/v1/responses');
    curl_setopt($handle, CURLOPT_USERPWD, 'auth_id:auth_secret');
    curl_setopt($handle, CURLOPT_POSTFIELDS, $data);
    curl_setopt($handle, CURLOPT_CAINFO, dirname(__FILE__).'/cert_bundle.crt');
    curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, 1);
    curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1);
    $result = curl_exec($handle);
    $statusCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
    curl_close($handle);
    
    //echo $statusCode;
    echo '<pre>';
    print_r(json_decode($result, true));
    echo '</pre>';
  • Node.JS
    var request = require('request');
    request.post({
        url: 'https://api.fonenode.com/v1/responses',
        auth: {username: 'auth_id', password: 'auth_secret'},
        form: {
          text: 'Which is your favorite football team? Press one for Manchester United. Two for Chelsea. Three for Arsenal. Four for Liverpool.',
          retries: 3,
          get_digits: true,
          choices: [
                       {
                           digit: 1,
                           label: 'Manchester United',
                           text: 'You selected Manchester United. Great!'
                       },
                       {
                           digit: 2,
                           label: 'Chelsea',
                           text: 'You selected Chelsea. Wow!'
                       },
                       {
                           digit: 3,
                           label: 'Arsenal',
                           text: 'You selected Chelsea. Up gunners!'
                       },
                       {
                           digit: 4,
                           label: 'Liverpool',
                           text: 'You selected Liverpool. Beautiful!'
                       },
          ],
          wrong_choice_response: 'Sorry, you have made a wrong selection.'
        }
      }, function(err, response, body) {
        if (err)
          return console.log(err);
    
        console.log(body);
      });

2. List Responses

List responses you have created.

URL: https://api.fonenode.com/v1/responses

Method: GET

Parameters:

  • limit: Optional. Number of numbers to return. Defaults to 20.

  • offset: Optional. The result offset for pagination.

Sample Code

  • Curl
    curl https://api.fonenode.com/v1/responses \
                -u auth_id:auth_secret
  • PHP
    $handle = curl_init();
    curl_setopt($handle, CURLOPT_URL, 'https://api.fonenode.com/v1/responses');
    curl_setopt($handle, CURLOPT_USERPWD, 'auth_id:auth_secret');
    curl_setopt($handle, CURLOPT_CAINFO, dirname(__FILE__).'/cert_bundle.crt');
    curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, 1);
    curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1);
    $result = curl_exec($handle);
    $statusCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
    curl_close($handle);
    
    //echo $statusCode;
    echo '<pre>';
    print_r(json_decode($result, true));
    echo '</pre>';
  • Node.JS
    var request = require('request');
    request.get({
        url: 'https://api.fonenode.com/v1/responses',
        auth: {username: 'auth_id', password: 'auth_secret'}
      }, function(err, response, body) {
        if (err)
          return console.log(err);
    
        console.log(body);
      });

Sample Response

{
  "total": 1,
  "count": 1,
  "offset": 0,
  "limit": 20,
  "data": [
    {
      "date": "2013-10-16T07:26:43.209Z",
      "text": "Hello Bae",
      "voice": "woman",
      "id": "525e3fb3b218980d35000001"
    }
  ]
}

3. Get A Response

Get details about a response.

URL: https://api.fonenode.com/v1/responses/{RESPONSE_ID}

Method: GET

Sample Code

  • Curl
    curl https://api.fonenode.com/v1/responses/525e3fb3b218980d35000001 \
        -u auth_id:auth_secret
  • PHP
    $handle = curl_init();
    curl_setopt($handle, CURLOPT_URL, 'https://api.fonenode.com/v1/responses/525e3fb3b218980d35000001');
    curl_setopt($handle, CURLOPT_USERPWD, 'auth_id:auth_secret');
    curl_setopt($handle, CURLOPT_CAINFO, dirname(__FILE__).'/cert_bundle.crt');
    curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, 1);
    curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1);
    $result = curl_exec($handle);
    $statusCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
    curl_close($handle);
    
    //echo $statusCode;
    echo '<pre>';
    print_r(json_decode($result, true));
    echo '</pre>';
  • Node.JS
    var request = require('request');
    request.get({
        url: 'https://api.fonenode.com/v1/responses/525e3fb3b218980d35000001',
        auth: {username: 'auth_id', password: 'auth_secret'}
      }, function(err, response, body) {
        if (err)
          return console.log(err);
    
        console.log(body);
      });

Sample Response

{
  "date": "2013-10-16T07:26:43.209Z",
  "text": "Hello Bae",
  "voice": "woman",
  "id": "525e3fb3b218980d35000001"
}

4. Delete A Response

URL: https://api.fonenode.com/v1/responses/{RESPONSE_ID}

Method: DELETE

Sample Code

  • Curl
    curl https://api.fonenode.com/v1/responses/525e3fb3b218980d35000001 \
      -u auth_id:auth_secret \
      -X DELETE
  • PHP
    $handle = curl_init();
    curl_setopt($handle, CURLOPT_URL, 'https://api.fonenode.com/v1/responses/525e3fb3b218980d35000001');
    curl_setopt($handle, CURLOPT_USERPWD, 'auth_id:auth_secret');
    curl_setopt($handle, CURLOPT_CAINFO, dirname(__FILE__).'/cert_bundle.crt');
    curl_setopt($handle, CURLOPT_CUSTOMREQUEST, "DELETE");
    curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, 1);
    curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1);
    $result = curl_exec($handle);
    $statusCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
    curl_close($handle);
    
    //echo $statusCode;
    echo '<pre>';
    print_r(json_decode($result, true));
    echo '</pre>';
  • Node.JS
    var request = require('request');
    request.del({
        url: 'https://api.fonenode.com/v1/responses/525e3fb3b218980d35000001',
        auth: {username: 'auth_id', password: 'auth_secret'}
      }, function(err, response, body) {
        if (err)
          return console.log(err);
    
        console.log(body);
      });

Sample Response

{
  "id": "525e3fb3b218980d35000001"
}

Calls

Use the call resource to make and manage calls.

1. Quick call

The quick call method allows you make a quick call without creating a response. This is ideal for situations where you don't want to create a response because it won't be reusable - number verification for example. You simply pass the text and other parameters directly to this method.

If you will be saying the same thing many times, or will be getting digit input from users, use the Make call method. This way you can create a single reusable response for your calls.

URL: https://api.fonenode.com/v1/calls/quick

Method: POST

Parameters:

  • to: Number to call. International format. For multiple numbers, send in an array of numbers. See pricing for prices to different countries.

  • text: Text to be read out or URL of an mp3 file to be played.

  • voice: Optional. Response voice. woman or man. Defaults to woman.

  • from: A number to use as the caller id. This number needs to be a verified number on the system. See numbers/verify for how to verify your number through the API.

  • callback_url: optional. If you supply a callback URL, the call details will be sent to your URL once fired. The following parameters are sent via POST

    • cost - cost of the call.
    • call_id - Id of the call
    • from - the caller number
    • to - the receiver number
    • type - the call type. inbound or outbound
    • token - your API secret to confirm request is coming from us. If this value is different from the API secret of your account, then the request is not from Fonenode

Sample Code

  • Curl
    curl https://api.fonenode.com/v1/calls/quick \
      -u auth_id:auth_secret \
      -d to=2348031164915 \
      -d from=2348054027312 \
      -d "text=Group meeting by six. Don't miss it."
  • PHP
    $data = array(
          'to' => '2348031164915',
          'from' => '2348054027312',
          'text' => 'Group meeting by six. Don't miss it.'
        );
    $handle = curl_init();
    curl_setopt($handle, CURLOPT_URL, 'https://api.fonenode.com/v1/calls/quick');
    curl_setopt($handle, CURLOPT_USERPWD, 'auth_id:auth_secret');
    curl_setopt($handle, CURLOPT_POSTFIELDS, $data);
    curl_setopt($handle, CURLOPT_CAINFO, dirname(__FILE__).'/cert_bundle.crt');
    curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, 1);
    curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1);
    $result = curl_exec($handle);
    $statusCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
    curl_close($handle);
    
    //echo $statusCode;
    echo '<pre>';
    print_r(json_decode($result, true));
    echo '</pre>';
  • Node.JS
    var request = require('request');
    request.post({
        url: 'https://api.fonenode.com/v1/calls/quick',
        auth: {username: 'auth_id', password: 'auth_secret'},
        form: {
          to: '2348031164915',
          from: '2348054027312',
          text: 'Group meeting by six. Don't miss it.'
        }
      }, function(err, response, body) {
        if (err)
          return console.log(err);
    
        console.log(body);
      });

Sample Response

Status code: 201

{
  "fired": [
    {
      "id": "525fe631034e00db3f000001",
      "number": "2348031164915"
    }
  ],
  "errors": []
}

2. Make Call

Make calls to one or more numbers using a response already created.

Method: POST

Parameters:

  • to: Number to call. International format. For multiple numbers, send in an array of numbers. See pricing for prices to different countries.

  • response_id: id of the response. This or an ivr_id should be present in the request.

  • ivr_id: id of the IVR menu to use. This or a response_id should be present in the request.

    If an ivr_id is used, an optional headers array can be attached to the IVR simultaneously when firing the call

  • from: A number to use as the caller id. This number needs to be a verified number on the system. See numbers/verify for how to verify your number through the API.

  • callback_url: optional. If you supply a callback URL, the call details will be sent to your URL once fired. The following parameters are sent via POST

    • cost - cost of the call.
    • call_id - Id of the call
    • from - the caller number
    • to - the receiver number
    • type - the call type. inbound or outbound
    • token - your API secret to confirm request is coming from us. If this value is different from the API secret of your account, then the request is not from Fonenode

Sample Code

  • Curl
    curl https://api.fonenode.com/v1/calls \
            -u auth_id:auth_secret \
            -d response_id=332fae67c0de453f3e000001 \
            -d to[0]=2348031164915 \
            -d to[1]=2348064969235
  • PHP
    $data = array(
          'to' => '2348031164915',
          'response_id' => '332fae67c0de453f3e000001'
        );
    $handle = curl_init();
    curl_setopt($handle, CURLOPT_URL, 'https://api.fonenode.com/v1/calls');
    curl_setopt($handle, CURLOPT_USERPWD, 'auth_id:auth_secret');
    curl_setopt($handle, CURLOPT_POSTFIELDS, $data);
    curl_setopt($handle, CURLOPT_CAINFO, dirname(__FILE__).'/cert_bundle.crt');
    curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, 1);
    curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1);
    $result = curl_exec($handle);
    $statusCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
    curl_close($handle);
    
    //echo $statusCode;
    echo '<pre>';
    print_r(json_decode($result, true));
    echo '</pre>';
  • Node.JS
    var request = require('request');
    request.post({
        url: 'https://api.fonenode.com/v1/calls',
        auth: {username: 'auth_id', password: 'auth_secret'},
        form: {
          to: '2348031164915',
          response_id: '332fae67c0de453f3e000001'
        }
      }, function(err, response, body) {
        if (err)
          return console.log(err);
    
        console.log(body);
      });

Sample Response

Status code: 201

{
  "fired": [
    {
      "id": "525fe631034e00db3f000001",
      "number": "2348031164915"
    },
    {
      "id": "525fe631034e00db3f000002",
      "number": "2348064969235"
    }
  ],
  "errors": []
}

3. List Calls

List inbound and outbound calls via your account.

Method: GET

Parameters:

  • limit: Optional. Number of results to return. Defaults to 20. Maximum of 100

  • offset: Optional. The result offset for pagination.

  • to: Optional. Show calls to this number.

  • from: Optional. Show calls from this number.

  • date_from: Optional. List calls starting from this date.

  • date_to: Optional. List calls till this date.

  • filter: Optional. Parameter to filter results on. Value can be picked, notpicked, called, notcalled, outbound or inbound.

PS: Dates must be in valid ISO8601 or RFC2822 format.

Sample Code

  • Curl
    curl https://api.fonenode.com/v1/calls \
                -u auth_id:auth_secret
  • PHP
    $handle = curl_init();
    curl_setopt($handle, CURLOPT_URL, 'https://api.fonenode.com/v1/calls');
    curl_setopt($handle, CURLOPT_USERPWD, 'auth_id:auth_secret');
    curl_setopt($handle, CURLOPT_CAINFO, dirname(__FILE__).'/cert_bundle.crt');
    curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, 1);
    curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1);
    $result = curl_exec($handle);
    $statusCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
    curl_close($handle);
    
    //echo $statusCode;
    echo '<pre>';
    print_r(json_decode($result, true));
    echo '</pre>';
  • Node.JS
    var request = require('request');
    request.get({
        url: 'https://api.fonenode.com/v1/calls',
        auth: {username: 'auth_id', password: 'auth_secret'}
      }, function(err, response, body) {
        if (err)
          return console.log(err);
    
        console.log(body);
      });

Sample Response

{
  "total": 2,
  "count": 2,
  "offset": 0,
  "limit": 20,
  "data": [
    {
      "called": true,
      "date": "2013-10-30T08:49:56.833Z",
      "duration": 60,
      "from": "2348000000000",
      "picked": true,
      "response_id": "526fb1fa13d4432c6f000004",
      "to": "2348181119144",
      "type": "outbound",
      "id": "5270c15497ee30df0e000006"
    },
    {
      "called": true,
      "date": "2013-10-30T08:44:52.579Z",
      "duration": 60,
      "from": "2348000000000",
      "picked": true,
      "response_id": "5570c70377ee30be0e000003",
      "text": "This is a quick call test.",
      "to": "2348069024479",
      "type": "outbound",
      "voice": "WOMAN",
      "id": "5570c70377ee30be0e000003"
    }
  ]
}

4. Get A Call

Get details about a call.

Method: GET

Sample Code

  • Curl
    curl https://api.fonenode.com/v1/calls/525e3fb3b218980d35000001 \
        -u auth_id:auth_secret
  • PHP
    $handle = curl_init();
    curl_setopt($handle, CURLOPT_URL, 'https://api.fonenode.com/v1/calls/525e3fb3b218980d35000001');
    curl_setopt($handle, CURLOPT_USERPWD, 'auth_id:auth_secret');
    curl_setopt($handle, CURLOPT_CAINFO, dirname(__FILE__).'/cert_bundle.crt');
    curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, 1);
    curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1);
    $result = curl_exec($handle);
    $statusCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
    curl_close($handle);
    
    //echo $statusCode;
    echo '<pre>';
    print_r(json_decode($result, true));
    echo '</pre>';
  • Node.JS
    var request = require('request');
    request.get({
        url: 'https://api.fonenode.com/v1/calls/525e3fb3b218980d35000001',
        auth: {username: 'auth_id', password: 'auth_secret'}
      }, function(err, response, body) {
        if (err)
          return console.log(err);
    
        console.log(body);
      });

Sample Response

{
  called: 1,
  duration: 32,
  from: '08023009719',
  to: '23414412537',
  type: 'inbound',
  date: '2015-05-08T15:09:29.127Z',
  id: '554cd1a9b29ede6d17ec2aba'
}

Numbers

If you want to create an application that requires people to call in, you can get a custom number and assign a response to it. The following methods allow you to interact with the number resource.

1. Available numbers

Returns available numbers you can purchase for inbound calls.

Method: GET

Parameters:

  • limit: Optional. Number of numbers to return. Defaults to 20.

  • offset: Optional. The result offset for pagination. Default is 0. For next the next page, it will be 1, then 2, and so on.

Sample Code

  • Curl
    curl https://api.fonenode.com/v1/numbers/available \
        -u auth_id:auth_secret
  • PHP
    $handle = curl_init();
    curl_setopt($handle, CURLOPT_URL, 'https://api.fonenode.com/v1/numbers/available');
    curl_setopt($handle, CURLOPT_USERPWD, 'auth_id:auth_secret');
    curl_setopt($handle, CURLOPT_CAINFO, dirname(__FILE__).'/cert_bundle.crt');
    curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, 1);
    curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1);
    $result = curl_exec($handle);
    $statusCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
    curl_close($handle);
    
    //echo $statusCode;
    echo '<pre>';
    print_r(json_decode($result, true));
    echo '</pre>';
  • Node.JS
    var request = require('request');
    request.get({
        url: 'https://api.fonenode.com/v1/numbers/available',
        auth: {username: 'auth_id', password: 'auth_secret'}
      }, function(err, response, body) {
        if (err)
          return console.log(err);
    
        console.log(body);
      });

2. My numbers

Returns numbers you own.

Method: GET

Parameters:

  • limit: Optional. Number of numbers to return. Defaults to 20.
  • offset: Optional. The result offset for pagination. Default is 0. For next the next page, it will be 1, then 2, and so on.

Sample Code

  • Curl
    curl https://api.fonenode.com/v1/numbers \
        -u auth_id:auth_secret
  • PHP
    $handle = curl_init();
    curl_setopt($handle, CURLOPT_URL, 'https://api.fonenode.com/v1/numbers');
    curl_setopt($handle, CURLOPT_USERPWD, 'auth_id:auth_secret');
    curl_setopt($handle, CURLOPT_CAINFO, dirname(__FILE__).'/cert_bundle.crt');
    curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, 1);
    curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1);
    $result = curl_exec($handle);
    $statusCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
    curl_close($handle);
    
    //echo $statusCode;
    echo '<pre>';
    print_r(json_decode($result, true));
    echo '</pre>';
  • Node.JS
    var request = require('request');
    request.get({
        url: 'https://api.fonenode.com/v1/numbers',
        auth: {username: 'auth_id', password: 'auth_secret'}
      }, function(err, response, body) {
        if (err)
          return console.log(err);
    
        console.log(body);
      });

Sample Response

{
  count: 2,
  offset: 0,
  data:[
    {
      id: '52ca46d9f355f257a96c412c',
      number: '23414405105',
      response_id: '512e9356f3fa18c029e3b91d'
    },
    {
      id: '51b7c0bdbb86e153d8db4056',
      number: '23414405577'
    }
  ]
}

3. Get a number

Returns details about a number.

Sample Code

  • Curl
    curl https://api.fonenode.com/v1/numbers/52ca46d9f355f257a96c412c \
        -u auth_id:auth_secret
  • PHP
    $handle = curl_init();
    curl_setopt($handle, CURLOPT_URL, 'https://api.fonenode.com/v1/numbers/52ca46d9f355f257a96c412c');
    curl_setopt($handle, CURLOPT_USERPWD, 'auth_id:auth_secret');
    curl_setopt($handle, CURLOPT_CAINFO, dirname(__FILE__).'/cert_bundle.crt');
    curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, 1);
    curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1);
    $result = curl_exec($handle);
    $statusCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
    curl_close($handle);
    
    //echo $statusCode;
    echo '<pre>';
    print_r(json_decode($result, true));
    echo '</pre>';
  • Node.JS
    var request = require('request');
    request.get({
        url: 'https://api.fonenode.com/v1/numbers/52ca46d9f355f257a96c412c',
        auth: {username: 'auth_id', password: 'auth_secret'}
      }, function(err, response, body) {
        if (err)
          return console.log(err);
    
        console.log(body);
      });

Sample Response

{
  id: '52ca46d9f355f257a96c412c',
  number: '23414405105',
  response_id: '512e9356f3fa18c029e3b91d'
}

4. Purchase a number

Purchase a number from available numbers.

Method: POST

Parameters:

  • id: id of the number. Required.

  • months: Optional. number of months you want to purchase for. Defaults to 1.

  • Curl
    curl https://api.fonenode.com/v1/numbers \
            -u auth_id:auth_secret \
            -d id=332fae67c0de453f3e000001
  • PHP
    $data = array(
          'id' => '332fae67c0de453f3e000001'
        );
    $handle = curl_init();
    curl_setopt($handle, CURLOPT_URL, 'https://api.fonenode.com/v1/numbers');
    curl_setopt($handle, CURLOPT_USERPWD, 'auth_id:auth_secret');
    curl_setopt($handle, CURLOPT_POSTFIELDS, $data);
    curl_setopt($handle, CURLOPT_CAINFO, dirname(__FILE__).'/cert_bundle.crt');
    curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, 1);
    curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1);
    $result = curl_exec($handle);
    $statusCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
    curl_close($handle);
    
    //echo $statusCode;
    echo '<pre>';
    print_r(json_decode($result, true));
    echo '</pre>';
  • Node.JS
    var request = require('request');
    request.post({
        url: 'https://api.fonenode.com/v1/numbers',
        auth: {username: 'auth_id', password: 'auth_secret'},
        form: {
          id: '332fae67c0de453f3e000001'
        }
      }, function(err, response, body) {
        if (err)
          return console.log(err);
    
        console.log(body);
      });

Sample Response

{
  "id": "525e3fb3b218980d35000002",
  "expires": "2013-12-30T08:52:14.667Z"
}

5. Renew a number

Renew a number you've earlier purchased.

Method: PUT.

Parameters:

  • months: number of months you want to purchase for. Optional. Defaults to 1.

Sample Code

  • Curl
    curl https://api.fonenode.com/v1/numbers/525e3fb3b218980d35000002 \
      -u auth_id:auth_secret \
      -X PUT
  • PHP
    $handle = curl_init();
    curl_setopt($handle, CURLOPT_URL, 'https://api.fonenode.com/v1/numbers/525e3fb3b218980d35000002');
    curl_setopt($handle, CURLOPT_USERPWD, 'auth_id:auth_secret');
    curl_setopt($handle, CURLOPT_CAINFO, dirname(__FILE__).'/cert_bundle.crt');
    curl_setopt($handle, CURLOPT_CUSTOMREQUEST, "PUT");
    curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, 1);
    curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1);
    $result = curl_exec($handle);
    $statusCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
    curl_close($handle);
    
    //echo $statusCode;
    echo '<pre>';
    print_r(json_decode($result, true));
    echo '</pre>';
  • Node.JS
    var request = require('request');
    request.put({
        url: 'https://api.fonenode.com/v1/numbers/525e3fb3b218980d35000002',
        auth: {username: 'auth_id', password: 'auth_secret'}
      }, function(err, response, body) {
        if (err)
          return console.log(err);
    
        console.log(body);
      });

Sample Response

{
  "id": "525e3fb3b218980d35000002",
  "expires": "2013-12-30T08:52:14.667Z"
}

6. Deactivate number

Release a number you've earlier purchased.

Method: DELETE.

Sample Code

  • Curl
    curl https://api.fonenode.com/v1/numbers/525e3fb3b218980d35000002 \
      -u auth_id:auth_secret \
      -X DELETE
  • PHP
    $handle = curl_init();
    curl_setopt($handle, CURLOPT_URL, 'https://api.fonenode.com/v1/numbers/525e3fb3b218980d35000002');
    curl_setopt($handle, CURLOPT_USERPWD, 'auth_id:auth_secret');
    curl_setopt($handle, CURLOPT_CAINFO, dirname(__FILE__).'/cert_bundle.crt');
    curl_setopt($handle, CURLOPT_CUSTOMREQUEST, "DELETE");
    curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, 1);
    curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1);
    $result = curl_exec($handle);
    $statusCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
    curl_close($handle);
    
    //echo $statusCode;
    echo '<pre>';
    print_r(json_decode($result, true));
    echo '</pre>';
  • Node.JS
    var request = require('request');
    request.del({
        url: 'https://api.fonenode.com/v1/numbers/525e3fb3b218980d35000002',
        auth: {username: 'auth_id', password: 'auth_secret'}
      }, function(err, response, body) {
        if (err)
          return console.log(err);
    
        console.log(body);
      });

Sample Response

{
  "id": "525e3fb3b218980d35000002"
}

7. Update number response

Attach or change the response, IVR callback URL or SMS url of a number.

Method: PUT.

Parameters: (any of)

  • response_id: id of the response.

  • ivr_id: id of the IVR.

  • sms_url: URL where incoming messages to number will be forward to. See attach number to an SMS endpoint for more details

Sample Code

  • Curl
    curl https://api.fonenode.com/v1/numbers/525e3fb3b218980d35000002 \
      -u auth_id:auth_secret \
      -d response_id=332fae67c0de453f3e000001 \
      -X PUT
  • PHP
    $data = array('response_id' => '332fae67c0de453f3e000001');
    $handle = curl_init();
    curl_setopt($handle, CURLOPT_URL, 'https://api.fonenode.com/v1/numbers/525e3fb3b218980d35000002');
    curl_setopt($handle, CURLOPT_USERPWD, 'auth_id:auth_secret');
    curl_setopt($handle, CURLOPT_POSTFIELDS, $data);
    curl_setopt($handle, CURLOPT_CAINFO, dirname(__FILE__).'/cert_bundle.crt');
    curl_setopt($handle, CURLOPT_CUSTOMREQUEST, "PUT");
    curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, 1);
    curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1);
    $result = curl_exec($handle);
    $statusCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
    curl_close($handle);
    
    //echo $statusCode;
    echo '<pre>';
    print_r(json_decode($result, true));
    echo '</pre>';
  • Node.JS
    var request = require('request');
    request.put({
        url: 'https://api.fonenode.com/v1/numbers/525e3fb3b218980d35000002',
        auth: {username: 'auth_id', password: 'auth_secret'},
        form: {response_id: '332fae67c0de453f3e000001'}
      }, function(err, response, body) {
        if (err)
          return console.log(err);
    
        console.log(body);
      });

Sample Response

{
  "id": "525e3fb3b218980d35000002"
}

Billing

This resource allows you access to your billing results.

1. List

List your billing history.

Method: GET.

Parameters:

  • limit: Optional. Number of numbers to return. Defaults to 20.

  • offset: Optional. The result offset for pagination.

  • filter: Optional. Parameter to filter results on. Value can be numbers, outbound or inbound for number charges, outbound call charges and inbound charges respectively.

Sample Code

  • Curl
    curl https://api.fonenode.com/v1/billing \
        -u auth_id:auth_secret
  • PHP
    $handle = curl_init();
    curl_setopt($handle, CURLOPT_URL, 'https://api.fonenode.com/v1/billing');
    curl_setopt($handle, CURLOPT_USERPWD, 'auth_id:auth_secret');
    curl_setopt($handle, CURLOPT_CAINFO, dirname(__FILE__).'/cert_bundle.crt');
    curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, 1);
    curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1);
    $result = curl_exec($handle);
    $statusCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
    curl_close($handle);
    
    //echo $statusCode;
    echo '<pre>';
    print_r(json_decode($result, true));
    echo '</pre>';
  • Node.JS
    var request = require('request');
    request.get({
        url: 'https://api.fonenode.com/v1/billing',
        auth: {username: 'auth_id', password: 'auth_secret'}
      }, function(err, response, body) {
        if (err)
          return console.log(err);
    
        console.log(body);
      });

Sample Response

{
  "total": 1,
  "count": 1,
  "offset": 0,
  "limit": 20,
  "data": [
    {
      "amount": 15,
      "type": "call/outbound",
      "text": "Outbound call to 2348181119144",
      "object": "2348181119144",
      "resource_id": "526fb1fa13d4432c6f000004",
      "date": "2013-10-30T08:52:14.667Z",
      "id": "5270c1be86ee30be0e000008"
    }
  ]
}

SMS

Fonenode SMS allows you receive and send SMS on local numbers (long codes). You simply purchase a number and attach it to an SMS endpoint. Incoming SMS to the number is forwarded to the endpoint and from there you can decide to interact with the sender in whatever way you prefer - even send a reply (using the send method).

Some use cases

  • Interactive SMS solutions
  • User subscription services
  • Two factor authentication
  • Two way messaging
  • SMS request solutions
  • Marketing campaigns

1. Attach number to an SMS endpoint

Once you get your number, you will want to attach it to an SMS endpoint. The endpoint is where incoming text messages are forwarded to. The following parameters are sent to the endpoint via POST:

  • from - the sender's number
  • to - your number
  • text - the text message

Note that this will only work for SMS enabled numbers on the Fonenode network. To request an SMS enabled number, send a mail to help@fonenode.com

Method: GET.

Parameters:

  • sms_url

Sample Code

  • Curl
    curl https://api.fonenode.com/v1/numbers/525e3fb3b218980d35000002
       -d 'sms_url=http://site.com/myendpoint' \
       -u auth_id:auth_secret \
       -X PUT
  • PHP
    $data = array('sms_url' => 'http://site.com/myendpoint');
    $handle = curl_init();
    curl_setopt($handle, CURLOPT_URL, 'https://api.fonenode.com/v1/numbers/525e3fb3b218980d35000002');
    curl_setopt($handle, CURLOPT_USERPWD, 'auth_id:auth_secret');
    curl_setopt($handle, CURLOPT_CAINFO, dirname(__FILE__).'/cert_bundle.crt');
    curl_setopt($handle, CURLOPT_CUSTOMREQUEST, "PUT");
    curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, 1);
    curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1);
    $result = curl_exec($handle);
    $statusCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
    curl_close($handle);
    
    //echo $statusCode;
    echo '<pre>';
    print_r(json_decode($result, true));
    echo '</pre>';
  • Node.JS
    var request = require('request');
    request.put({
        url: 'https://api.fonenode.com/v1/numbers/525e3fb3b218980d35000002',
        auth: {username: 'auth_id', password: 'auth_secret'},
        form: {sms_url: 'http://site.com/myendpoint'}
      }, function(err, response, body) {
        if (err)
          return console.log(err);
    
        console.log(body);
      });

2. Get received messages

In addition to forwarding the messages to your SMS endpoint, they will be stored on the server as well. To list all your messages, simply send a GET request to /sms/inbox

Parameters:

  • limit: Optional. Number of numbers to return. Defaults to 20.

  • offset: Optional. The result offset for pagination. Default is 0. For next the next page, it will be 1, then 2, and so on.

  • number: Optional. Mobile number attached to your account. Helpful, in case you have more than one number on your account.

Sample Code

  • Curl
    curl https://api.fonenode.com/v1/sms/inbox \
                -u auth_id:auth_secret
  • PHP
    $handle = curl_init();
    curl_setopt($handle, CURLOPT_URL, 'https://api.fonenode.com/v1/sms/inbox');
    curl_setopt($handle, CURLOPT_USERPWD, 'auth_id:auth_secret');
    curl_setopt($handle, CURLOPT_CAINFO, dirname(__FILE__).'/cert_bundle.crt');
    curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, 1);
    curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1);
    $result = curl_exec($handle);
    $statusCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
    curl_close($handle);
    
    //echo $statusCode;
    echo '<pre>';
    print_r(json_decode($result, true));
    echo '</pre>';
  • Node.JS
    var request = require('request');
    request.get({
        url: 'https://api.fonenode.com/v1/sms/inbox',
        auth: {username: 'auth_id', password: 'auth_secret'}
      }, function(err, response, body) {
        if (err)
          return console.log(err);
    
        console.log(body);
      });

Sample Response

{
"count": 1,
"offset": 0,
"total": 1,
"data": [
   {
    "id": "525e3fb3b218980d35000002",
    "from": "2348181019102",
     "to": "234803841727",
     "text": "Should I still expect you today?",
     "date": "2013-10-16T07:26:43.209Z"
   }
]}

3. Get an SMS messages

You may be interested in getting the details of just one message. Simply send a GET request with the message ID

Sample Code

  • Curl
    curl https://api.fonenode.com/v1/sms/inbox/525e3fb3b218980d35000002 \
                -u auth_id:auth_secret
  • PHP
    $handle = curl_init();
    curl_setopt($handle, CURLOPT_URL, 'https://api.fonenode.com/v1/sms/inbox/525e3fb3b218980d35000002');
    curl_setopt($handle, CURLOPT_USERPWD, 'auth_id:auth_secret');
    curl_setopt($handle, CURLOPT_CAINFO, dirname(__FILE__).'/cert_bundle.crt');
    curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, 1);
    curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1);
    $result = curl_exec($handle);
    $statusCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
    curl_close($handle);
    
    //echo $statusCode;
    echo '<pre>';
    print_r(json_decode($result, true));
    echo '</pre>';
  • Node.JS
    var request = require('request');
    request.get({
        url: 'https://api.fonenode.com/v1/sms/inbox/525e3fb3b218980d35000002',
        auth: {username: 'auth_id', password: 'auth_secret'}
      }, function(err, response, body) {
        if (err)
          return console.log(err);
    
        console.log(body);
      });

Sample Response

{
  "id": "525e3fb3b218980d35000002",
  "from": "2348181019102",
  "to": "234803841727",
  "text": "Should I still expect you today?",
  "date": "2013-10-16T07:26:43.209Z"
}

4. Send SMS message

To send an SMS message, make a POST request to /sms. The following would happen:

  • This will return a 201 response containing the message id.
  • The outbox message with the above message id would contain a delivery field.
  • The status field will assume any of the following values:
    • Pending
    • Delivered
    • Expired
    • Unknown
  • When the delivery status in the outbox changes, the sms_url callback will be fired with the relevant delivery information: id, from, to, delivery, text, date

Parameters:

  • from: This should be your number (the number attached to the SMS)

  • to: The receiver. Ensure this is in international format

  • text: The message you are sending

Sample Response

{
  "id": "525e3fb3b218980d35000002"
}

5. Get sent messages

To view messages you have sent, send a GET request to /sms/outbox

Parameters:

  • limit: Optional. Number of numbers to return. Defaults to 20.

  • offset: Optional. The result offset for pagination. Default is 0. For next the next page, it will be 1, then 2, and so on.

  • number: Optional. Mobile number attached to your account. Helpful, in case you have more than one number on your account.

Sample Code

  • Curl
    curl https://api.fonenode.com/v1/sms/outbox \
                -u auth_id:auth_secret
  • PHP
    $handle = curl_init();
    curl_setopt($handle, CURLOPT_URL, 'https://api.fonenode.com/v1/sms/outbox');
    curl_setopt($handle, CURLOPT_USERPWD, 'auth_id:auth_secretp');
    curl_setopt($handle, CURLOPT_CAINFO, dirname(__FILE__).'/cert_bundle.crt');
    curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, 1);
    curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1);
    $result = curl_exec($handle);
    $statusCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
    curl_close($handle);
    
    //echo $statusCode;
    echo '<pre>';
    print_r(json_decode($result, true));
    echo '</pre>';
  • Node.JS
    var request = require('request');
    request.get({
        url: 'https://api.fonenode.com/v1/sms/outbox',
        auth: {username: 'auth_id', password: 'auth_secret'}
      }, function(err, response, body) {
        if (err)
          return console.log(err);
    
        console.log(body);
      });

Sample Response

{
"count": 1,
"offset": 0,
"total": 1,
"data": [
   {
    "id": "525e3fb3b218980d35000002",
    "from": "234803841727",
    "to": "2348181019102",
    "text": "I will be around soon",
    "date": "2013-10-16T07:30:43.209Z",
    "delivery": "pending"
   }
]}

IVR

This is a description of the IVR process and expected responses from provided callback URLs.

How it works

When there is an incoming call to the attached number, or when a call is instantiated with the IVR, Fonenode visits the attached URL (see create IVR) and follows the instructions in the response. The following JSON attributes (lowercase; case-sensitive) form the instructions that can be set in the response:

  • say: A text to read out to the caller. This can also be an absolute path to an MP3 file
  • callback_url: An absolute URL where input by the caller will be forwarded to. You can use the callback URL to create another IVR menu by outputting new set of instructions for Fonenode. Fonenode follows every instruction in callback URLs till non exist, or the user terminates. (See example below). If this parameter is not specified, no input is expected from the caller. The call terminates after the say, call or sms action.
  • sms: SMS to be sent back to the user.

    {
      "sms": "This is a demo SMS"
    }							

    To send the SMS using a custom sender id, the sms variable should be an objet with a source and text parameter. e.g

    {
      "sms": {
       "text": "This is a demo SMS",
       "source": "fonenode"
      }

  • call: A number to place a call to. Should be in international format.
  • record_url: Url where a recording from the user will be POST'ed' to. Format of data to record_url:

    {
      "url": "https://s3.amazon.com/recordings_2013/example.mp3",
      "duration": "8"
    }							

  • voice: MAN or WOMAN. If say is a text to be read out, this can be used to specify the voice. Defaults to WOMAN
  • no_input_text: Text or absolute path to an MP3 if the user didn't enter a text after a specific period
  • number_of_digits: By default, a one digit response is expected from the caller. If you are expecting more, specify the number of digits here.
  • finish_on_key: If you would rather capture the user input after a certain key is pressed, you can use this parameter to specify the key. e.g

    {
      "say": "Enter your age. Press # when done.",
      "finish_on_key": "#",
      "callback_url": "http://example-ivr.com/menu-1"
    }
    								

The following is sent via POST to the callback URL

  1. to: The receiver's number. If this is an inbound call, it will be your Fonenode number
  2. from: The caller's number. If it is an outbound call, this is your Fonenode number
  3. digits: The caller's input
  4. call_id: ID of the call

Example

Imagine we need to build an IVR for a comapny support line like this:

"Welcome to Wayne Enterprises. Press 1 for a list of our subsidiaries. Press 2 for our foundations."

  • First we create a root menu script where all calls coming to the number is forwarded to. Remember, we just need to output a set of instructions for Fonenode. Here is what our root_menu script will look like:

    {
      "say": "Welcome to Wayne Enterprises. Press 1 for a list of our subsidiaries. Press 2 for our foundations.",
      "callback_url": "http://wayne.entp/ivr/root_menu_options"
    }
    						

  • Next, we create our IVR and point it to our root_menu script using the redirect_to parameter of the Create IVR method.

  • Now that we've created an IVR and pointed it to a URL, we can go ahead to build the other menus. From our root_menu, the user input is sent to root_menu_options and Fonenode redirects there for further instructions. Let's go ahead to build that.

    <?php
    // root_menu_options
    $digits = $_POST['digits'];
    $json = array();
    if ($digits == '*') {
      // Go back to root menu and read options again
      header('http://wayne.entp/ivr/root_menu');
      exit;
    }
    else if ($digits == '1') {
      $json['say'] = 'Our subsidiaries include: aerospace, biotech, medical,
       electronics, construction and steel';
      // => {"say":"Our subsidiaries include..."}
    }
    else if ($digits == '2') {
      $json['say'] = 'Our foundations are the Thomas Wayne Foundation
       and the Martha Wayne Foundation';
      // => {"say":"Our foundations are..."}
    }
    else {
      $json = array(
      	'say' => 'Invalid input. Press * to listen again',
    	'callback_url' => 'http://wayne.entp/ivr/root_menu_options'
    	);
    }
    echo json_encode($json);
    ?>
    						

  • It's really that simple. Just add a callback_url if you want to go deeper and within that URL response, give the instructions you want Fonenode to follow.

Methods

1. Create IVR

Create the IVR object

Method: POST

Parameters:

  • redirect_to: Url to redirect to and get instructions.

  • headers: Optional. Array containing headers that should be added to the request when the redirect_to url is called.

  • name: Optional. Name to identify the IVR, gets returned in the json to the callback_url.

Sample Code

  • Curl
    curl https://api.fonenode.com/v1/ivr \
        -u auth_id:auth_secret \
        -d redirect_to="http://fonenoderedirect.com" \
        -d headers[Authorization]="iijiofdoimimUIUI="
    						
  • PHP
    $data = array('redirect_to' => 'http://fonenoderedirect.com');
    $handle = curl_init();
    curl_setopt($handle, CURLOPT_URL, 'https://api.fonenode.com/v1/ivr');
    curl_setopt($handle, CURLOPT_USERPWD, 'auth_id:auth_secret');
    curl_setopt($handle, CURLOPT_POSTFIELDS, $data);
    curl_setopt($handle, CURLOPT_CAINFO, dirname(__FILE__).'/cert_bundle.crt');
    curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, 1);
    curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1);
    $result = curl_exec($handle);
    $statusCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
    curl_close($handle);
    
    //echo $statusCode;
    echo '<pre>';
    print_r(json_decode($result, true));
    echo '</pre>';
  • Node.JS
    var request = require('request');
    request.post({
        url: 'https://api.fonenode.com/v1/ivr',
        auth: {username: 'auth_id', password: 'auth_secret'},
        form: {redirect_to: 'http://fonenoderedirect.com', headers: {Authorization: 'iijiofdoimimUIUI='}}
      }, function(err, response, body) {
        if (err)
          return console.log(err);
    
        console.log(body);
      });

Sample Response

{
  "id": "55760b5dd92098a72cfcc82b"
}
				

2. Get all IVRs

List all IVRs created by user

Method: GET

Sample Code

  • Curl
    curl https://api.fonenode.com/v1/ivr \
        -u auth_id:auth_secret \
    						
  • PHP
    $handle = curl_init();
    curl_setopt($handle, CURLOPT_URL, 'https://api.fonenode.com/v1/ivr');
    curl_setopt($handle, CURLOPT_USERPWD, 'auth_id:auth_secret');
    curl_setopt($handle, CURLOPT_CAINFO, dirname(__FILE__).'/cert_bundle.crt');
    curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, 1);
    curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1);
    $result = curl_exec($handle);
    $statusCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
    curl_close($handle);
    
    //echo $statusCode;
    echo '<pre>';
    print_r(json_decode($result, true));
    echo '</pre>';
  • Node.JS
    var request = require('request');
    request.get({
        url: 'https://api.fonenode.com/v1/ivr',
        auth: {username: 'auth_id', password: 'auth_secret'}
      }, function(err, response, body) {
        if (err)
          return console.log(err);
    
        console.log(body);
      });

Sample Response

{
  "total": 1,
  "limit": 20,
  "count": 1,
  "offset": 0,
  "data": [
    {
      "date": "2015-06-08T21:38:37.613Z",
      "redirect_to": "http://fonenoderedirect.com",
      "id": "55760b5dd92098a72cfcc82b"
    }
  ]
}
				

3. Delete IVR

Deletes an IVR

Method: DELETE

Sample Code

  • Curl
    curl https://api.fonenode.com/v1/ivr/55717647d92098a72cfcc67b \
        -u auth_id:auth_secret \
        -X DELETE
  • PHP
    $handle = curl_init();
    curl_setopt($handle, CURLOPT_URL, 'https://api.fonenode.com/v1/ivr/55717647d92098a72cfcc67b');
    curl_setopt($handle, CURLOPT_USERPWD, 'auth_id:auth_secret');
    curl_setopt($handle, CURLOPT_CAINFO, dirname(__FILE__).'/cert_bundle.crt');
    curl_setopt($handle, CURLOPT_CUSTOMREQUEST, "DELETE");
    curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, 1);
    curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1);
    $result = curl_exec($handle);
    $statusCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
    curl_close($handle);
    
    //echo $statusCode;
    echo '<pre>';
    print_r(json_decode($result, true));
    echo '</pre>';
  • Node.JS
    var request = require('request');
    request.del({
        url: 'https://api.fonenode.com/v1/ivr/55717647d92098a72cfcc67b',
        auth: {username: 'auth_id', password: 'auth_secret'}
      }, function(err, response, body) {
        if (err)
          return console.log(err);
    
        console.log(body);
      });
{
  "id": "55717647d92098a72cfcc67b"
}
				

4. Update IVR

Update IVR

Method: PUT

Parameters:

  • redirect_to:. Url to redirect to.

  • headers: Optional. Array containing headers that should be added to the request when the redirect_to url is called.

Sample Code

  • Curl
    curl https://api.fonenode.com/v1/ivr/55760b5dd92098a72cfcc82b \
        -u auth_id:auth_secret \
        -d redirect_to='http://fonenodenew.com' -X PUT
  • PHP
    $handle = curl_init();
    curl_setopt($handle, CURLOPT_URL, 'https://api.fonenode.com/v1/ivr/55760b5dd92098a72cfcc82b');
    curl_setopt($handle, CURLOPT_USERPWD, 'auth_id:auth_secret');
    curl_setopt($handle, CURLOPT_CAINFO, dirname(__FILE__).'/cert_bundle.crt');
    curl_setopt($handle, CURLOPT_CUSTOMREQUEST, "PUT");
    curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, 1);
    curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1);
    $result = curl_exec($handle);
    $statusCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
    curl_close($handle);
    
    //echo $statusCode;
    echo '<pre>';
    print_r(json_decode($result, true));
    echo '</pre>';
  • Node.JS
    var request = require('request');
    request.put({
        url: 'https://api.fonenode.com/v1/ivr/55760b5dd92098a72cfcc82b',
        auth: {username: 'auth_id', password: 'auth_secret'},
        form: {redirect_to: 'http://fonenodenew.com'}
      }, function(err, response, body) {
        if (err)
          return console.log(err);
    
        console.log(body);
      });
{
  "id": "55760b5dd92098a72cfcc82b"
}
				

OTP

The One Time Password (OTP) resource helps you quickly authenticate users on your platform with their mobile numbers. The user receives a call immediately bearing his code as the caller id, when the user picks, the call is hungup.

You should store the response from calling this API, as the code in the response is the same number that calls the user.

1. Create An OTP

Create a 5 digit OTP code and fires a call (a flash actually) to the desired number.

URL: https://api.fonenode.com/v1/otp

Method: POST

Parameters:

  • to: Number to make an OTP call to. Must be in International format. E.g 234811056859

  • code (Optional): 5-6 digit code to use as OTP code, if not supplied, a default 5 digit code will be auto generated. E.g 12345

 

Sample Code:

  • Curl
    POST https://api.fonenode.com/v1/otp
    
    $ curl https://api.fonenode.com/v1/otp \
      -u auth_id:auth_secret \
      -d "to=2348110568529" \
    						
  • PHP
    $data = array('to' => '2348110568529');
    $handle = curl_init();
    curl_setopt($handle, CURLOPT_URL, 'https://api.fonenode.com/v1/otp');
    curl_setopt($handle, CURLOPT_USERPWD, 'auth_id:auth_secret');
    curl_setopt($handle, CURLOPT_POSTFIELDS, $data);
    curl_setopt($handle, CURLOPT_CAINFO, dirname(__FILE__).'/cert_bundle.crt');
    curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, 1);
    curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1);
    $result = curl_exec($handle);
    $statusCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
    curl_close($handle);
    
    //echo $statusCode;
    echo '<pre>';
    print_r(json_decode($result, true));
    echo '</pre>';
  • Node.JS
    var request = require('request');
    request.post({
        url: 'https://api.fonenode.com/v1/otp',
        auth: {username: 'auth_id', password: 'auth_secret'},
        form: {
          to: '2348110568529',
        }
      }, function(err, response, body) {
        if (err)
          return console.log(err);
    
        console.log(body);
      });
{
"code": "23452"
}