Python sdk filter for UserAggregateQueryFilter

I am not sure how to use the filter query to pass in as a body. Could you please help me with this.
api_instance = PureCloudPlatformClientV2.UsersApi()
body = PureCloudPlatformClientV2.UserAggregationQuery()
body.filter =

Query for user aggregates

api_response = api_instance.post_analytics_users_aggregates_query(body)

Hi,

The filter parameter is a nested object so you will need to create a UserAggregateQueryFilter object and set the query filter to that object. The api explorer will show the types of all the parameters for this endpoint if you need help https://developer.genesys.cloud/devapps/api-explorer#post-api-v2-analytics-users-aggregates-query

api_instance = PureCloudPlatformClientV2.UsersApi(apiclient);

body = PureCloudPlatformClientV2.UserAggregationQuery() 
filterObj = PureCloudPlatformClientV2.UserDetailQueryFilter()

filterObj.type = "value"
body.filter = filterObj

I hope this helps.

Regards,
Declan

Thanks Declan for your answer really appreciate it and now i get an idea of how to pass in the filter object.

So while passing in the filter object, i am getting an error. is this the right way to do it.

body = PureCloudPlatformClientV2.UserAggregationQuery()
filterObj = PureCloudPlatformClientV2.UserAggregateQueryFilter()
filterObj.type = "and"
queryPredicate = PureCloudPlatformClientV2.UserAggregateQueryPredicate()
body.filter = filterObj
body.predicates = queryPredicate

Query for user aggregates

api_response = api_instance.post_analytics_users_aggregates_query(body)

Hi,

You may be missing required fields or sending invalid values. Can you send a sample of your code and the error you are getting.

Regards,
Declan

Sure. Below is the code i am using.

apiclient = PureCloudPlatformClientV2.api_client.ApiClient().get_client_credentials_token(
GENESYS_CLOUD_CLIENT_ID, GENESYS_CLOUD_CLIENT_SECRET
)
PureCloudPlatformClientV2.configuration.access_token = apiclient.access_token

api_instance = PureCloudPlatformClientV2.UsersApi()
body = PureCloudPlatformClientV2.UserAggregationQuery()
filterObj = PureCloudPlatformClientV2.UserAggregateQueryFilter()
filterObj.type = "and"
queryPredicate = PureCloudPlatformClientV2.UserAggregateQueryPredicate()
body.interval = '2023-05-15T10:10:10/2023-05-16T10:10:10'
body.metrics = ["tAgentRoutingStatus", "tOrganizationPresence", "tSystemPresence"]
body.filter = filterObj
body.predicates = queryPredicate

api_response = api_instance.post_analytics_users_aggregates_query(body)

Note: Is there a way i can get the data by passing any default values for filter. Because i just need to pull all the data for the given time interval.

Hi,

Could you show the error you are getting also. I did notice a problem with your code though. You are setting the predicates on the body object but it is actually a parameter on the filter object so your code should look similar to this:

body.filter = filterObj
predicatedArray = []
filterObj.predicates = predicatedArray.append(PureCloudPlatformClientV2.UserAggregateQueryPredicate())

You may also need to set values for the filter parameters and the nested objects in order to get a response.

Filter seems to be a required field so you will need to include it unfortunately.

Regards,
Declan

Thanks Declan, This is the error i am getting.

HTTP response body: {"message":"Conjunction predicate must have 1 or more predicates","code":"bad.request","status":400,"messageParams":{},"contextId":"5c4c0556-8287-4ff9-994c-176df98b0226","details":[],"errors":[]}

Hi,

You will need to specify a userId in the predicates in order to perform the query. Do do this in python will look something like this:

body = PureCloudPlatformClientV2.UserAggregationQuery()
filterObj = PureCloudPlatformClientV2.UserAggregateQueryFilter()
predicate1 = PureCloudPlatformClientV2.UserAggregateQueryPredicate()

predicatedArray = []
predicate1.dimension = "userId"
predicate1.value = "9e840ed1-d5ff-4f52-997d-eeskfe82b"
predicatedArray.append(predicate1)
filterObj.type = "or"
filterObj.predicates = predicatedArray

body.interval = '2020-05-15T10:10:10/2023-05-16T10:10:10'
body.metrics = ["tAgentRoutingStatus", "tOrganizationPresence", "tSystemPresence"]
body.filter = filterObj

You may need to play around with this to get your desired result. This article may also help you understand how to use the endpoint to get your desired result.

Regards,
Declan

Thanks Declan,

This really helps me to move forward. Really appreciate the effort in solving my problem.

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.