News & Announcements User Community Developer Community

Welcome to the RingCentral Community

Please note the community is currently under maintenance and is read-only.

Search
Make sure to review our Terms of Use and Community Guidelines.
  Please note the community is currently under maintenance and is read-only.
Home » Developers
Retrieving All Company Call Logs for Realtime Custom Wallboards
Tags: call logs
Jul 16, 2020 at 5:52pm   •   3 replies  •  0 likes
Joe Ramos

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;

}



}


2 Answers
answered on Jul 21, 2020 at 8:46am  

Will try that, thanks for the code sample.


 0
answered on Jul 21, 2020 at 8:21am  

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)
        });
}



 0



A new Community is coming to RingCentral!

Posts are currently read-only as we transition into our new platform.

We thank you for your patience
during this downtime.

Try Workflow Builder

Did you know you can easily automate tasks like responding to SMS, team messages, and more? Plus it's included with RingCentral Video and RingEX plans!

Try RingCentral Workflow Builder

PRODUCTS
RingEX
Message
Video
Phone
OPEN ECOSYSTEM
Developer Platform
APIs
Integrated Apps
App Gallery
Developer support
Games and rewards

RESOURCES
Resource center
Blog
Product Releases
Accessibility
QUICK LINKS
App Download
RingCentral App login
Admin Portal Login
Contact Sales
© 1999-2024 RingCentral, Inc. All rights reserved. Legal Privacy Notice Site Map Contact Us