I was able to call Ring Central Analytics API for the user performance, such as missed calls, aggregated by user by a fixed date range, for example, from 2022-03-23 to 2022-03-24. How can I get the API response by user by a dynamic date range, for example, yesterday, given today is 2022-03-25. My ultimate goal is to have the API response daily as below. I also posted my script below for your reference.
# desired table (after parsed api json into tabular format)
date | user | missed_call_count |
2022-03-23 | user_1 | 10 |
2022-03-23 | user_2 | 20 |
2022-03-24 | user_1 | 30 |
# script
{ "grouping": { "groupBy": "Users", "ids": [] }, "timeSettings": { "timeRange": { "timeFrom": "2022-03-23T00:00:00.000Z", "timeTo": "2022-03-24T00:00:00.000Z" }, "advancedTimeSettings": { "timeZone": "US/Eastern", "includeDays": [ "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" ], "includeHours": [ { "from": "00:00", "to": "23:59" } ] } }, "responseOptions": { "counters": { "allCalls": { "aggregationType": "Sum" }, "timers": { "allCallsDuration": { "aggregationType": "Sum" } } } } }
I was able to put the dynamic date range into the json body, using python.
from datetime import datetime, timedelta # load json object with the fixed date range aggregate_json_file = 'aggregate_data_request.json' json_request_object = json.load(open(aggregate_json_file)) # set dynamic date range json_request_object['timeSettings']['timeRange']['timeFrom'] = datetime.now().strftime('%Y-%m-%d %H:%M:%S') json_request_object['timeSettings']['timeRange']['timeTo'] = (datetime.now() + timedelta(days=1)).strftime('%Y-%m-%d %H:%M:%S') # print json object with the dynamic date range print(json_request_object)
Thank you @Suyash Joshi . Yes I am using AWS Glue ELT tool to run the this API daily so making the date range as a variable and passing this to the script works well for my case.
Hi @Ngoc Nguyen it seems like you were able to answer your own problem which is great. Yes by making it a variable and passing the date/time for each day you should be able to get the report daily. You can further run this code as a nightly cron job or use a serverless function that is scheduled to run every day. Let us know if you need any further help.
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