How to pull call logs with an API
Tags: getting started
Oct 10, 2017 at 8:04am • 7 replies • 0 likes
yg-tech
I need to get RC call logs in a csv format every 15 minutes or less to my CRM can someone help with this?
7 Answers
Phong Vu, this is working great, but it only pulls down 100 records maximum. I increase the time to more than 15 minutes and I sometimes have more than 100 calls in the time period. How do set the number of records to pull?
0
Hi,
Here is the working code in Node JS.
You need to install the RingCentral SDK for Node JS
npm install ringcentral --save
and install the dotenv so you can use the .env to keep your app and login credentials
Code:
var RC = require('ringcentral')
require('dotenv').load()
var rcsdk = new RC({
server:process.env.SERVER,
appKey: process.env.APP_KEY,
appSecret:process.env.APP_SECRET
})
var platform = rcsdk.platform()
login()
function login() {
platform.login({
username:process.env.USERNAME,
password:process.env.PASSWORD
})
.then(function(resp){
readCallLog()
setInterval(function(){
readCallLog()
}, 60 * 15 * 1000); // repeat reading call-log every 15 mins
})
.catch(function(e){
throw e
})
}
function readCallLog(){
var date = new Date()
var time = date.getTime()
// 15-min period
var less15Min = time - (60 * 15 * 1000)
var from = new Date(less15Min)
var dateFrom = from.toISOString()
var dateTo = date.toISOString()
var params = {}
// See the API reference for more request parameters
params['type'] = 'Voice'
params['view'] = 'Detailed'
params['dateFrom'] = dateFrom.replace('/', ':')
params['dateTo'] = dateTo.replace('/', ':')
console.log(params.dateFrom)
console.log(params.dateTo)
platform.get('/account/~/extension/~/call-log', params)
.then(function(resp){
var json = resp.json()
if (json.records.length > 0){
// Check the API documentation for call log data fields then add whatever you are interested
var cvs = 'uri,startTime,duration,type,direction,action,result,to_name,from_name,transport'
for (var record of json.records){
cvs += "\r\n"
cvs += record.uri + ','
cvs += record.startTime + ','
cvs += record.duration + ','
cvs += record.type + ','
cvs += record.direction + ','
cvs += record.action + ','
cvs += record.result + ','
if (record.to.name != undefined)
cvs += record.to.name + ','
else
cvs += 'null,'
if (record.from.name != undefined)
cvs += record.from.name + ','
else
cvs += 'null,'
cvs += record.transport
}
var fs = require('fs')
// add to your CRM db
// for demo, I write the data to a file
fs.writeFile('call_log_'+dateTo+'.csv', cvs, function(err) {
if(err)
console.log(err);
else
console.log("call log is saved.");
})
}
})
.catch(function(e){
throw e
})
}
I am here to help you. So no payment :)
Bests,
Phong
Here is the working code in Node JS.
You need to install the RingCentral SDK for Node JS
npm install ringcentral --save
and install the dotenv so you can use the .env to keep your app and login credentials
Code:
var RC = require('ringcentral')
require('dotenv').load()
var rcsdk = new RC({
server:process.env.SERVER,
appKey: process.env.APP_KEY,
appSecret:process.env.APP_SECRET
})
var platform = rcsdk.platform()
login()
function login() {
platform.login({
username:process.env.USERNAME,
password:process.env.PASSWORD
})
.then(function(resp){
readCallLog()
setInterval(function(){
readCallLog()
}, 60 * 15 * 1000); // repeat reading call-log every 15 mins
})
.catch(function(e){
throw e
})
}
function readCallLog(){
var date = new Date()
var time = date.getTime()
// 15-min period
var less15Min = time - (60 * 15 * 1000)
var from = new Date(less15Min)
var dateFrom = from.toISOString()
var dateTo = date.toISOString()
var params = {}
// See the API reference for more request parameters
params['type'] = 'Voice'
params['view'] = 'Detailed'
params['dateFrom'] = dateFrom.replace('/', ':')
params['dateTo'] = dateTo.replace('/', ':')
console.log(params.dateFrom)
console.log(params.dateTo)
platform.get('/account/~/extension/~/call-log', params)
.then(function(resp){
var json = resp.json()
if (json.records.length > 0){
// Check the API documentation for call log data fields then add whatever you are interested
var cvs = 'uri,startTime,duration,type,direction,action,result,to_name,from_name,transport'
for (var record of json.records){
cvs += "\r\n"
cvs += record.uri + ','
cvs += record.startTime + ','
cvs += record.duration + ','
cvs += record.type + ','
cvs += record.direction + ','
cvs += record.action + ','
cvs += record.result + ','
if (record.to.name != undefined)
cvs += record.to.name + ','
else
cvs += 'null,'
if (record.from.name != undefined)
cvs += record.from.name + ','
else
cvs += 'null,'
cvs += record.transport
}
var fs = require('fs')
// add to your CRM db
// for demo, I write the data to a file
fs.writeFile('call_log_'+dateTo+'.csv', cvs, function(err) {
if(err)
console.log(err);
else
console.log("call log is saved.");
})
}
})
.catch(function(e){
throw e
})
}
I am here to help you. So no payment :)
Bests,
Phong
1
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