Home Forums Voip Optimisation Custom Features Reply To: Custom Features

Mark Hanson
Keymaster
Post count: 1105

Hello Nishit thank you for your updates, in #11588 and #11589,
we have also got your lost post with your code below:
==================================Nishit’s Message Starts ===================================
Make some changes for to get bulk data but i can reach up to 700 records at a time and it also take time to generate the xlsx file. But after amount I got “gateway time out” error.

And this is my request method to get all DID numbers from API
$params = array(
“i_customer” => i_customer,
‘get_total’=> 1,
“check_usage”=>1,
“with_extended_info” => 1,
“limit” => 50000,
);

And My curl request is as bellow

$curl = curl_init();
$searchArray = array(‘auth_info’ => ‘{“session_id”:”‘ . $session_id . ‘”}’, ‘params’ => json_encode($params));

curl_setopt_array($curl, array(
CURLOPT_URL => ‘https://mybilling.nanotelecom.org/rest/DID/get_number_list’,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => ”,
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => ‘POST’,
CURLOPT_POSTFIELDS => $searchArray
));
$response = curl_exec($curl);
curl_close($curl);
$DIDNumber = json_decode($response);

return $DIDNumber;

and for above request i got this error :

{“faultcode”:”internal_server_error”,”faultstring”:”Internal server error”}

=========================Nishit’s Message Ends ================================

and we have addressed your code to the senior developer and here is what they responded to you.

=========================Message from the senior developer starts ========================

You cannot make it work by increasing limits, you should use a combination of “limit” and “offset” parameters in order to fetch small batches of numbers and then merge results. You can use the attached script as an example of the idea – it receives 500 numbers (0-499), then 500 next numbers (500-999), then 500 next numbers (1000-1499) and repeats it until all numbers are received.

—————-CODE SAMPLE BELOW:

#!/usr/bin/php
i_customer,
“get_total”=> 1,
“check_usage”=>1,
“with_extended_info” => 1,
“limit” => 500,
“offset” => 0,
);

$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => ‘https://mybilling.nanotelecom.org/rest/DID/get_number_list’,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => ”,
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => ‘POST’,
));

$all_numbers = array();

while (true) {
echo(“Fetching records from ” . $params[“offset”] . ” to ” . $params[“offset”] + $params[“limit”] . “\n”);
curl_setopt($curl, CURLOPT_POSTFIELDS, array(
“auth_info” => $auth_info,
“params” => json_encode($params),
));
$response = curl_exec($curl);
$response = json_decode($response);

if ($response->number_list) {
$all_numbers = array_merge($all_numbers, $response->number_list);
$params[“offset”] = $params[“offset”] + count($response->number_list);
if (count($response->number_list) < $params["limit"]) { break; } } else { break; } } curl_close($curl); echo("Total number of records: " . count($all_numbers) . "\n"); ?>

Please let us know how it works
Cheers