Skip to main content

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🇲🇲ss.fffZ",CultureInfo.InvariantCulture);


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


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

//string endSyncDateTime = DateTime.UtcNow.ToString("yyyy-MM-ddTHH🇲🇲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;

}



}


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



Will try that, thanks for the code sample.


Reply