This TelecomsXChange API allows you to get an updated complete list of all country codes + country names and network operator name via a single API call.


The best way to demonstrate how this works is via an open source example that you can use as a base to build on top of it.


The demo app (Live demo here) we are publishing will have a search input and once you start typing the country code it will show a complete list of all prefixes for this country along with network operator names. then when you search it will utilize the rate lookup api to get high/low rates from the market for this specific code.


There will be two files in this example: index.php and get_zoom_list.php 


First file (index.php):


<?php



// Buyer login in TelecomsXChange
$api_login ="ENTER YOUR BUYER USERNAME HERE";

//Your API key (Get one on www.telecomsxchange.com/ )

$api_key = "ENTER YOUR API KEY"; 


// initialising CURL

$ch = curl_init();

//controller is a script name, so in case lookup.php controller is lookup
$controller = "lookup";

//unix timestamp to ensure that signature will be valid temporary
$ts = time();

//compose signature concatenating controller api_key api_login and unix timestamp
$signature = hash( 'sha256', $controller .  $api_key   . $api_login  . $ts);

$search = $_REQUEST['search'];
$searchform = (int) $_REQUEST['searchform'];
$type = $_REQUEST['type'];

$params = array(
                'ts' => $ts,  //Provide TS
                'signature' => $signature,
                'webapi' => '1',   //required field by tcxc api
                'api_login' => $api_login,
                'searchform' => '1'  //required field
                );

if($searchform) {

        $params['type'] = $type;

        if(preg_match("/^(\d+)/", $search, $matches)) {
                $params['prefix'] = $matches[1];
        } else {
                $params['country'] = $search;
        }

        //query against api. URL
        curl_setopt($ch, CURLOPT_URL,"https://members.telecomsxchange.com/$controller.php");
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS,
        http_build_query($params));
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $server_output = curl_exec ($ch);
        $result = json_decode($server_output, true);
        $rates = $result['rates'];

        curl_close ($ch);

}

?>

<html>
        <head>
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" integrity="sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M" crossorigin="anonymous">
        <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">

        <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
        <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>


<script>
$().ready(function() {


    $( "#search" ).autocomplete({
      source: "get_zoom_list.php"
    });



  });
  </script>


        </head>

        <body>

        <div class="jumbotron">

                <form action="index.php">
                <input type=hidden name=searchform value=1>
                <div class="input-group">
                  <input type="text" id=search name=search class="form-control" placeholder="Enter country code or country name" aria-describedby="basic-addon1" value="<?php echo "$search";?>" >

                  <select name='type' class="form-control">
                        <option value='ANY' <?php if($type == 'ANY') echo "SELECTED";?> >ANY</option>
                        <option value='NA'  <?php if($type == 'NA') echo "SELECTED";?>  >NA</option>
                        <option value='CLI' <?php if($type == 'CLI') echo "SELECTED";?> >CLI</option>
                        <option value='TDM' <?php if($type == 'TDM') echo "SELECTED";?>  >TDM</option>
                        <option value='NoCLI' <?php if($type == 'NoCLI') echo "SELECTED";?> >NoCLI</option>
                  </select>

                  <input type="submit" class="form-control" value="search">
                </div>
                </form>

        </div>

        <?php
                if($searchform)

                        if(count($rates)) {
                                $min_price_n = 100000.0 ;
                                $min_interval_1 = 1;
                                $min_interval_n = 1;

                                $max_price_n = 0.0;
                                $max_interval_1 = 1;
                                $max_interval_n = 1;

                                foreach($rates as $rate) {
                                        if($min_price_n > $rate['price_n']) {
                                                $min_price_n = $rate['price_n'];
                                                $min_interval_1 = $rate['interval_1'];
                                                $min_interval_n = $rate['interval_n'];
                                        }

                                        if($max_price_n < $rate['price_n']) {
                                                $max_price_n = $rate['price_n'];
                                                $max_interval_1 = $rate['interval_1'];
                                                $max_interval_n = $rate['interval_n'];
                                        }
                                }

                                echo "<div class='alert alert-success' role='alert'>Highest Price: $max_price_n [$max_interval_1.$max_interval_n]    |    Lowest Price: $min_price_n [$min_interval_1.$min_interval_n]</div>";



                        } else {
                                echo "<div class='alert alert-danger' role='alert'>No results found</div>";
                        }
        ?>


        </body>
</html>



Second file (get_zoom_list.php):


<?php

$q = $_REQUEST['term'];
// TelecomsXChange Buyer Username, get one at www.telecomsxchange.com/buyerjoin

$api_login ="ENTER YOUR BUYER USERNAME HERE";

//API key
$api_key = "ENTER YOUR API KEY"; 
// initialising CURL
$ch = curl_init();

//controller is a script name, so in case lookup.php controller is lookup
$controller = "get_zoom_list";

//unix timestamp to ensure that signature will be valid temporary
$ts = time();

//compose signature concatenating controller api_key api_login and unix timestamp
$signature = hash( 'sha256', $controller .  $api_key   . $api_login  . $ts);

$params = array(
                'ts' => $ts,  //provide TS
                'q' => $q,
                'api_login' => $api_login,
                'signature' => $signature,
                'webapi' => 1,
                //...

                );


//query against api. URL

//debug CURL?
//curl_setopt($ch, CURLOPT_VERBOSE, true);


curl_setopt($ch, CURLOPT_URL,"https://members.telecomsxchange.com/scripts/autocomplete/$controller.php");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,
http_build_query($params));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec ($ch);
curl_close ($ch);

//analyze JSON output
//echo "server_output:$server_output";
$response = json_decode($server_output, JSON_OBJECT_AS_ARRAY);
//print_r($response);
if($response['status'] == 'success' ) {
        header('Content-Type: application/json');
        echo json_encode($response['entries']);
}


?>



What you need to have to use this source code:


1- TelecomsXChange Buyer Account ( Sign up for one here: www.telecomsxchange.com/voice_api /

2- API Key (Generated from inside the portal after you signup)