Skip to main content

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)

dateusermissed_call_count
2022-03-23user_110
2022-03-23user_220
2022-03-24user_130


# 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)



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.


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.


Reply