question

Ngoc Nguyen avatar image
Ngoc Nguyen asked Ngoc Nguyen answered

How to get user performance API by dynamic date range?

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"

      }

     } 

    }

  }

}
rest api
1 comment
1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Ngoc Nguyen avatar image Ngoc Nguyen commented ·

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)


0 Likes 0 ·
Suyash Joshi avatar image
Suyash Joshi answered

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.

1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Ngoc Nguyen avatar image
Ngoc Nguyen answered

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.

1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Developer sandbox tools

Using the RingCentral Phone for Desktop, you can dial or receive test calls, send and receive test SMS or Fax messages in your sandbox environment.

Download RingCentral Phone for Desktop:

Tip: switch to the "sandbox mode" before logging in the app:

  • On MacOS: press "fn + command + f2" keys
  • On Windows: press "Ctrl + F2" keys