skip to Main Content

I am using CTM API for my web application. URL of docs is here. I am fetching data for list of activities and data arrived. But when I am passing parameters i.e. start_date and end_date the data does not change and only 10 rows are fetched and displayed.

My code is:

curl_setopt_array($curl, array(
    CURLOPT_URL => 'https://api.calltrackingmetrics.com/api/v1/accounts/'.$sub_account_id.'/calls?start_date='.$start_date.'&end_date='.$end_date,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => '',
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 0,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => 'GET',
    CURLOPT_HTTPHEADER => array(
      'Authorization: Basic '.$encoded_string,
      'Content-Type: application/json'
    ),
  ));

I am passing start_date and end_date parameters but receiving on first 10 rows. Am I doing something wrong?

Please guide me to this docs if I am doing anything wrong.

2

Answers


  1. You can try sending the parameters in other way i.e.

    $pData["account_id"]=$account_id;
    $pData["start_date"]=$start_date;
    $pData["end_date"]=$end_date;
    
    CURLOPT_POST => true,
    CURLOPT_POSTFIELDS => $pData,
    
    Login or Signup to reply.
  2. Your URL looks fine and if you are receiving first 10 rows only then the result is also fine. As per my perception from going through docs. There might be next page url in the response. And you can get all rows by iterating through loop while getting data from next page URL until the end page. You can do something like this

    $i=1; 
      $result_calls = array();
      $result = "";
      
      do {
         curl_setopt_array($curl, array(
          CURLOPT_URL => empty($result)? 'https://api.calltrackingmetrics.com/api/v1/accounts/'.$sub_account_id.'/calls?start_date='.$start_date.'&end_date='.$end_date : $result['next_page'],
          
          CURLOPT_RETURNTRANSFER => true,
          CURLOPT_ENCODING => '',
          CURLOPT_MAXREDIRS => 10,
          CURLOPT_TIMEOUT => 0,
          CURLOPT_FOLLOWLOCATION => true,
          CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
          CURLOPT_CUSTOMREQUEST => 'GET',
          CURLOPT_HTTPHEADER => array(
            'Authorization: Basic '.$encoded_string,
            'Content-Type: application/json'
          ),
        ));
    
        $response = curl_exec($curl);
    
        curl_close($curl);
    
        $result = json_decode($response, true);
    
        foreach ($result['calls'] as $key => $value) {
          array_push($result_calls, $value); 
        }
    
        
        $i++;
    
       } while ($i <= $result['total_pages']); 
    

    Hope this helps.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search