Nick2598 | 2024-03-19 19:07:40 UTC | #1
I have been working on using the /api/v2/analytics/users/aggregates/query to get 30 minute intervals for user status. I have included the query below. My issue is that when I run this query inside of python I get results as none. When I run this query inside of the Execute Request inside of the Analytics API explorer I get full results for this user.
api_instance = PureCloudPlatformClientV2.UsersApi();
body = PureCloudPlatformClientV2.UserAggregationQuery()
filterObj = PureCloudPlatformClientV2.UserAggregateQueryFilter()
predicate1 = PureCloudPlatformClientV2.UserAggregateQueryPredicate()
predicatedArray = []
predicate1.dimension = "userId"
predicate1.value = "6e63a163-d4d0-47ef-8f88-9ec81fedfb7e"
predicate1.operator = "matches"
predicate1.type = "dimension"
predicatedArray.append(predicate1)
filterObj.type = "or"
filterObj.predicates = predicatedArray
body.interval = '2024-03-18T00:00:00/2024-03-19T00:00:00'
body.group_by = ["userId"]
body.granularity = "PT30M"
body.metrics = ["tSystemPresence"]
body.filter = filterObj
print(body)
try:
api_response = api_instance.post_analytics_users_aggregates_query(body)
print(api_response)
except ApiException as e:
print("Exception when calling UsersApi->post_analytics_users_aggregates_query: %s\n" % e)
The body looks like this in the request:
{'alternate_time_dimension': None,
'filter': {'clauses': None,
'predicates': [{'dimension': 'userId',
'operator': 'matches',
'range': None,
'type': 'dimension',
'value': '6e63a163-d4d0-47ef-8f88-9ec81fedfb7e'}],
'type': 'or'},
'flatten_multivalued_dimensions': None,
'granularity': 'PT30M',
'group_by': ['userId'],
'interval': '2024-03-18T00:00:00/2024-03-19T00:00:00',
'metrics': ['tSystemPresence'],
'time_zone': None,
'views': None}
Any advice or guidance on this is appreciated, thank you!
Declan_ginty | 2024-03-20 12:08:14 UTC | #2
Hi Nick,
What is the request body you sending to sending in the api explorer?
Regards, Declan
Nick2598 | 2024-03-20 13:51:37 UTC | #3
Hi Delcan,
Here is the request body that I am sending in the api-explorer. The response I get is giving full data inside of the genesys api explorer
{
"interval": "2024-03-18T00:00:00/2024-03-19T00:00:00",
"granularity": "PT30M",
"groupBy": [
"userId"
],
"filter": {
"type": "or",
"predicates": [
{
"type": "dimension",
"dimension": "userId",
"operator": "matches",
"value": "6e63a163-d4d0-47ef-8f88-9ec81fedfb7e"
}
]
},
"metrics": [
"tSystemPresence"
]
}
Declan_ginty | 2024-03-20 14:43:37 UTC | #4
Hi Nick,
This might be due to some values being set as null when the request is sent. In some cases a value being set as null is not the same as it not being set and can change the data returned. Could you print print(body.to_json()) and then try the output of that print in api explorer and see if you get data returned?
Regards, Declan
Nick2598 | 2024-03-20 15:32:41 UTC | #5
Okay, so I put in as much information as possible, when I ran the request in the api explorer, when views were null or clauses were null I got a 500 response code.
I updated the information in my code to enter as much information as possible to prevent the nulls throwing it off. The only one I could not enter is range since range must be null when using the matches operator for a dimension predicate.
{"interval": "2024-03-18T00:00:00/2024-03-19T00:00:00", "granularity": "PT30M", "time_zone": "EST", "group_by": ["userId"], "filter": {"type": "or", "clauses": [{"type": "or", "predicates": [{"type": "dimension", "dimension": "userId", "operator": "matches", "value": "6e63a163-d4d0-47ef-8f88-9ec81fedfb7e"}]}], "predicates": [{"type": "dimension", "dimension": "userId", "operator": "matches", "value": "6e63a163-d4d0-47ef-8f88-9ec81fedfb7e", "range": null}]}, "metrics": ["tSystemPresence"], "flatten_multivalued_dimensions": "true", "views": [{"target": "tSystemPresence", "name": "Views", "function": "rangeBound", "range": {"gte": 0, "lt": 100000000000}}], "alternate_time_dimension": "eventTime"}
Here is the code the api explorer generated with the input
{
"timeZone": "EST",
"granularity": "PT30M",
"interval": "2024-03-18T00:00:00/2024-03-19T00:00:00",
"groupBy": [
"userId"
],
"filter": {
"type": "or",
"predicates": [
{
"type": "dimension",
"dimension": "userId",
"operator": "matches",
"value": "6e63a163-d4d0-47ef-8f88-9ec81fedfb7e",
"range": {
"gte": 0,
"lte": 1011010
}
}
],
"clauses": [
{
"type": "or",
"predicates": [
{
"type": "dimension",
"dimension": "userId",
"operator": "matches",
"value": "6e63a163-d4d0-47ef-8f88-9ec81fedfb7e"
}
]
}
]
},
"metrics": [
"tSystemPresence"
],
"flattenMultivaluedDimensions": true,
"views": [
{
"target": "tSystemPresence",
"name": "Views",
"function": "rangeBound",
"range": {
"gte": 0,
"lt": 100000000000
}
}
],
"alternateTimeDimension": "eventTime"
}
The api explorer is still giving me full information for this users 30 minute intervals.
The api response from this body in the python sdk request is still
{'results': None, 'system_to_organization_mappings': None}
Declan_ginty | 2024-03-20 15:41:14 UTC | #6
The only other reason I can think this is happening is perhaps you are using a different endpoint with the python sdk than you are on api explorer or you are using the python sdk in a different org than on api explorer
Nick2598 | 2024-03-20 18:05:27 UTC | #7
I don't believe so, I have multiple queries on the script that are all working perfectly besides this one so I know it is connected to the correct org.
As far as endpoint goes, I am running the code above and I believe they are the proper ones. It is the same as the python SDK code in the invocations on the /api/v2/analytics/users/aggregates/query which is where I am running the api explorer.
api_instance = PureCloudPlatformClientV2.UsersApi(); body = PureCloudPlatformClientV2.UserAggregationQuery() filterObj = PureCloudPlatformClientV2.UserAggregateQueryFilter()
apiresponse = apiinstance.postanalyticsusersaggregatesquery(body)
I have already checked my API's permissions and this App has the permission associated with a developer role so everything should be working properly.
Is there a way to submit a ticket about this? The code seems valid to me, the api is responsive, not sending any error codes, but just not delivering results.
Declan_ginty | 2024-03-20 18:41:02 UTC | #8
Yes you can open a ticket with care to report your problem.
Dustin_York | 2024-03-28 14:09:26 UTC | #9
Here is the query I run. It is a different time period and I am looking at different metrics but I am hitting the same endpoint query = { "metrics": ["tOrganizationPresence"], "interval": timerange, "granularity": "P1D", "groupBy": ["userId"], "filter": {"type": "and","predicates": [{ "value": userid, "dimension": "userId"}]}} the value is reading a variable, since I am looping through a list of userIds, and the timerange is also a variable in my code. The filter setup is different than what you are doing, maybe that is causing issues?
system | 2024-04-28 14:10:10 UTC | #10
This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.
This post was migrated from the old Developer Forum.
ref: 25291