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
Absolute novice needing help with an API. Help?
Tags: sdk
Sep 10, 2018 at 7:25am   •   2 replies  •  0 likes
matthew-nisbet

I am needing to have RC export a detailed call log for our business every hour or so (more frequently if possible) into either excel or Google Sheets and I would like this to be as automated a process as possible. I have very little coding experience but I think this might be the best way to get this done with about breaking the bank on zapier. Would someone be able to help get us set-up with something like this or at least walk me through how I could do it?

2 Answers
answered on Sep 12, 2018 at 11:34am  
Thank you so much.  This will be extremely helpful I believe.  I have started the creation of the application.  I am trying to get it to hook up to the existing accounts of our business and I am honestly a bit lost there. 

Honestly, with enough time and effort put in, I am sure that I could get this in the long run, especially since you have done all the heavy lifting already it looks like but is this something we would potentially be able to hire you to provide a finished product for us or are there folks with RC that offer that service?



 0
answered on Sep 10, 2018 at 12:03pm  
Hi Matthew,

What you need is really doable with the call log API. If you are familiar with Node JS and can run it locally on your machine, this little code can help you to see how it works. You just need to login the developer portal and create an app with the read call log permission. App platform type will be Server only (no UI). Copy your app Client ID and Client Secret to use in 

var RC = require('ringcentral')
var rcsdk = new RC({
  server:"https://platform.devtest.ringcentral.com",
  appKey: YOU_APP_CLIENT_ID,
  appSecret:YOUR_APP_CLIENT_SECRET
})
var platform = rcsdk.platform()
login()
function login() {
  platform.login({
    username:process.env.USERNAME,
    password:process.env.PASSWORD
  })
  .then(function(resp){
    console.log("readCallLog by timer")
    readCallLog()
    setInterval(function(){
        readCallLog()
      }, 60 * 60 * 1000); // repeat reading call-log every 60 mins
  })
  .catch(function(e){
    console.log(e)
    throw e
  })
}
function readCallLog(){
  console.log("timed")
  var date = new Date()
  var time = date.getTime()
  // 60-min period
  var lessXXMin = time - (60 * 60 * 1000)
  var from = new Date(lessXXMin)
  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("date from: " + params.dateFrom)
  console.log("date to: " + params.dateTo)
  var recordingId = ""
  platform.get('/account/~/extension/~/call-log', params)
  .then(function(resp){
    var json = resp.json()
    if (json.records.length > 0){
      var fs = require('fs')
      // 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){
        //console.log(JSON.stringify(record))
        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.hasOwnProperty('name'))
          cvs += record.to.name + ','
        else
          cvs += 'null,'
        if (record.hasOwnProperty('from')){
          if (record.from.hasOwnProperty('name'))
            cvs += record.from.name + ','
          else
            cvs += 'null,'
        }else
          cvs += 'null,'
        cvs += record.transport
        if (record.recording != undefined) {
          console.log("contentUri: " + record.recording.contentUri)
          recordingId = record.recording.id
          console.log(record.recording.contentUri)
          platform.get(record.recording.contentUri)
          .then(function(res) {
            console.log("ok")
            return res.response().buffer();
          })
          .then(function(buffer) {
            console.log("buffer")
            fs.writeFileSync(recordingId + '.mp3', buffer);
          })
          .catch(function(e){
            console.log(e)
            throw e
          })
        }
      }
      // add to your CRM  or other db
      // for demo, I write to a file
      fs.writeFile('call_log_'+dateTo+'.csv', cvs, function(err) {
        if(err)
          console.log(err);
        else
          console.log("call log is saved.");
      })
    }else {
      console.log("No log");
    }
  })
  .catch(function(e){
    throw e
  })
}
Let me know if you want in other programming languages.

+ Phong Vu 

 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

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