question

Joe Ramos avatar image
Joe Ramos asked Phong Vu edited

Retrieving All Company Call Logs for Realtime Custom Wallboards

Is there another way of doing this? we are running into a limit of 1000 records. We have a large company that we are writing a custom wall board monitoring app. We need to figure out the best approach, We are currently getting all of our call logs, but I am using the last modified date, and going back 1 hour. We are missing records, I am guessing because we are only bringing in 1000 records due to the limit and some are falling off. So how should we approach this without out the limit. Would love to figure out the FSync Isnyc, but how do we get all company logs in this manner and call legs etc...


Here is the code we are using for this.


if (lastSyncRecord != null)

{

DateTime lastSyncDateTime = lastSyncRecord.Value;


sDate = lastSyncDateTime.AddMinutes(-90);


string stringFormattedDate = sDate.ToString("yyyy-MM-ddTHH:mm:ss.fffZ",CultureInfo.InvariantCulture);


//Go 12 hours back from last value to retrieve records


//string startSyncDateTime = lastSyncDateTime.AddHours(-3).ToString("yyyy-MM-ddTHH:mm:ss.fffZ",CultureInfo.InvariantCulture);

//string endSyncDateTime = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss.fffZ",CultureInfo.InvariantCulture);


if (nextPageUrl == null)

{

//url = "https://" + hostBaseUrl + "/restapi/v1.0/account/~/call-log?dateFrom="+startSyncDateTime+"&dateTo="+endSyncDateTime+"&page=1&perPage=600&view=Detailed";

url = "https://" + hostBaseUrl + "/restapi/v1.0/account/~/call-log?view=Detailed&dateFrom="+stringFormattedDate+"&perPage=1000";


}

else

{

url = nextPageUrl;

}



}


call logs
3 comments
1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Phong Vu avatar image Phong Vu ♦♦ commented ·

Can you fist clean up your code, post only those lines which highlight your problem and also put the code in a code block to make it readable.

0 Likes 0 ·
Joe Ramos avatar image Joe Ramos Phong Vu ♦♦ commented ·

I updated the code above to only include the section that is relevant. Keep in mind the pull works and we normally do not have an issue with the data. The issue arises with some calls that , we think, are falling out of the limit. Example. WE are limited to 1000 records at a time. we have 220 users. We pull every 5 minutes, but since the API or back end updates the times when the call ends, such as a long call, we go back 90 minutes to make sure we are updating the calls and the legs accordingly with the new updated call time. So what we think is happening, is in that 90 minutes period at 220 users, we are exceeding the 1000 limit, and some calls are falling out of our retrieval. So we must not be approaching this the wrong way. Would love an example of how to pull all company calls with a larger organization. Closest to real time so we can proved wallboards for the call center.

0 Likes 0 ·
Joe Ramos avatar image Joe Ramos Phong Vu ♦♦ commented ·

Bump, not sure you seen the updated reply, please let us know, and or if there is a call in area.

0 Likes 0 ·
Phong Vu avatar image
Phong Vu answered Phong Vu edited

Here is some code snippet in Node JS to read large call logs with multiple pages. It shows one way how to deal with API rate limit also.

var SDK = require('ringcentral')

RINGCENTRAL_CLIENTID = "app-client-id";
RINGCENTRAL_CLIENTSECRET = "app-client-secret";
RINGCENTRAL_SERVER = 'https://platform.ringcentral.com'

RINGCENTRAL_USERNAME = "";
RINGCENTRAL_PASSWORD = "";
RINGCENTRAL_EXTENSION = "";

var rcsdk = new SDK({
      server: RINGCENTRAL_SERVER,
      appKey: RINGCENTRAL_CLIENTID,
      appSecret: RINGCENTRAL_CLIENTSECRET
  });
var platform = rcsdk.platform();
var startTime = 0
platform.login({
      username: RINGCENTRAL_USERNAME,
      password: RINGCENTRAL_PASSWORD,
      extension: RINGCENTRAL_EXTENSION
      })
      .then(function(resp) {
        var jsonObj = resp.response().heade
        use_dynamic_limit_value()
      });

function use_dynamic_limit_value(){
  startTime = Date.now()
  platform.get('/account/~/call-log', {
          dateFrom: "2020-01-01T00:00:00.000Z",
          view: "Simple",
          perPage: 1000
      })
      .then(function (resp) {
        console.log("======= WRITE RECORDS TO YOUR DB =======")
        for (var record of resp.json().records){
          console.log(JSON.stringify(record))
          console.log("======= ^^^^^ ========")
        }
        var navigationObj = resp.json().navigation
        if (navigationObj.hasOwnProperty("nextPage")){
          read_calllog_nextpage(navigationObj.nextPage.uri)
        }else{
          console.log("DONE - no next page")
        }
      });
}
function read_calllog_nextpage(url){
  platform.get(url)
    .then(function (resp) {
      console.log("======= WRITE RECORDS TO YOUR DB =======")
      for (var record of resp.json().records){
        console.log(JSON.stringify(record))
        console.log("======= ^^^^^ ========")
      }
      var jsonObj = resp.response().headers
      var limit = parseInt(jsonObj['_headers']['x-rate-limit-limit'][0])
      var limitRemaining = parseInt(jsonObj['_headers']['x-rate-limit-remaining'][0])
      var limitWindow = parseInt(jsonObj['_headers']['x-rate-limit-window'][0])

      var navigationObj = resp.json().navigation
      if (navigationObj.hasOwnProperty("nextPage")){
        var delayInterval = 0
        if (limitRemaining == 0){
            console.log("No remaining => calculate waiting time")
            var now = Date.now()
            var diff = now - startTime
            delayInterval = (limitWindow / limit) * 1000
            startTime = now + delayInterval
        }
        console.log("Read next page after " + delayInterval + " milliseconds")
        setTimeout(function(){
            read_calllog_nextpage(navigationObj.nextPage.uri)
        }, delayInterval)
      }else{
        console.log("DONE - no more next page")
      }
    });
}

As you said you want to read the data as near realtime as possible, there might be many calls being active when you read the call log. There are a few ways to deal with those call records and here is one of the possible ways. Call the company active calls API before each time you read the account call logs. keep the active calls' session id on a list, then keep track of those calls when they are completed (polling or using the telephony session notification) then read the call log with the sessionId to fetch the record and sync with your database.

function read_company_active_call(){
    platform.get('/account/~/active-calls',
              view: "Simple"
        })
        .then(function (resp) {
          var jsonObj = resp.json()
          for (var record of jsonObj.records){
            console.log(record.sessionId)
          }
        })
        .catch(function(e){
          console.log(e.message)
        });
}


1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Joe Ramos avatar image
Joe Ramos answered

Will try that, thanks for the code sample.

1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Developer sandbox tools

Using the RingCentral Phone for Desktop, you can dial or receive test calls, send and receive test SMS or Fax messages in your sandbox environment.

Download RingCentral Phone for Desktop:

Tip: switch to the "sandbox mode" before logging in the app:

  • On MacOS: press "fn + command + f2" keys
  • On Windows: press "Ctrl + F2" keys