Connecting API to Report page

  • 1
  • Question
  • Updated 3 weeks ago
I'm creating a basic API to pull our call logs to a csv. Easy enough except I'm trying to match the format. Right now the call log API extracts all the data exactly as it comes into the 'Call Log' page.

The issue is that our manual process was copying from the 'Call Detail' tab on the Reports page. I can go through the call log json and format everything so that the exported csv is pretty close to the format my only concern there is the logic for the "legs" to produce the same accurate output for the "Users" and "Queue Name" as the Reports page does. 

Is there a way to just connect the API directly to the Reports page rather than the call log and formatting the data? 

If not how do I set up the Reporting in my sandbox so that I can confirm my output vs the Report page.
Photo of Kevin Heuple

Kevin Heuple

  • 90 Points 75 badge 2x thumb

Posted 3 weeks ago

  • 1
Photo of Brandon Burchard

Brandon Burchard

  • 122 Points 100 badge 2x thumb
Have you tried scheduling these reports to be emailed as a csv instead of using the API to build this function? Depending on the plan you are subscribed to you should have this option. This is a much easier way and you can generate reports by extensions and email them to any email address. 
Photo of Kevin Heuple

Kevin Heuple

  • 90 Points 75 badge 2x thumb
I'm importing the CSV into our DB and trying to make it entirely automated.

So API runs on a scheduled job > saves last x days of call log to csv on server > job consumes csv and writes data to our database and deletes csv.
Photo of John Wang

John Wang, Official Rep

  • 4,862 Points 4k badge 2x thumb
If the CSV contains everything you need, you can programmatically retrieve the email if you have API access to the account. Standard email accounts generally have IMAP or POP protocol APIs that can be used. Also, if you send it to a developer email service like SparkPost, SendGrid, Mailgun, etc., you may be able to access the email and CSV via REST API. I've used IMAP to programmatically retrieve email in the past and it worked fine.

After you retrieve the email, you need to use a MIME parser to extract the CSV attachment from the email.
(Edited)
Photo of Phong Vu

Phong Vu, Devangelist

  • 2,136 Points 2k badge 2x thumb
Hi Kevin,

Just to confirm with you that there is no API to access the report page as you wish. However, with the call-log API, you can access the same call log dataset and can convert the JSON response to CSV format similar to the one you can download from the service web.

If you extract the format of your current report and let me know which fields you want to add into your db, I can help you write some sample code to convert the JSON response into CSV the way you want.

+ Phong
Photo of Kevin Heuple

Kevin Heuple

  • 90 Points 75 badge 2x thumb
Thank you. This is the exact information I need to extract and the headers from the report:


The only ones I've having a hard time with are the Users and Queue name. From the json format it looks like the array of legs for each call is formatted something like-
Leg[0] = Main Menu
Leg[1] = Extension or Queue selection
Leg[2] = Person Connected to is Leg[1] was a Queue Selection
(Edited)
Photo of Phong Vu

Phong Vu, Devangelist

  • 2,136 Points 2k badge 2x thumb
Hi Kevin,
Sorry for delayed response.
I am not so sure about the fields you want to import to your CVS format. You said that you want it the same as the report which is in my case I see this:
Type,Direction,From,To,Extension,Forwarded To,Name,Date,Time,Action,Action Result,Result Description,Duration,Included,Purchased
Also, in your example, are the from , to, start time on each row from each leg? or from the main response out of the legs object?