Legacy Dev Forum Posts

 View Only

Sign Up

Python sdk filter for UserAggregateQueryFilter

  • 1.  Python sdk filter for UserAggregateQueryFilter

    Posted 06-05-2025 18:09

    praveenkumar.dm | 2023-05-23 14:35:07 UTC | #1

    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

    apiresponse = apiinstance.postanalyticsusersaggregatesquery(body)


    Declan_ginty | 2023-05-24 09:58:10 UTC | #2

    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


    praveenkumar.dm | 2023-05-24 11:51:33 UTC | #3

    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

    apiresponse = apiinstance.postanalyticsusersaggregatesquery(body)


    Declan_ginty | 2023-05-24 12:02:33 UTC | #4

    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


    praveenkumar.dm | 2023-05-24 12:26:16 UTC | #5

    Sure. Below is the code i am using.

    apiclient = PureCloudPlatformClientV2.apiclient.ApiClient().getclientcredentialstoken( GENESYSCLOUDCLIENTID, GENESYSCLOUDCLIENTSECRET ) PureCloudPlatformClientV2.configuration.accesstoken = apiclient.accesstoken

    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

    apiresponse = apiinstance.postanalyticsusersaggregatesquery(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.


    Declan_ginty | 2023-05-24 15:20:18 UTC | #6

    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


    praveenkumar.dm | 2023-05-24 16:46:18 UTC | #7

    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":[]}


    Declan_ginty | 2023-05-25 14:17:47 UTC | #8

    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


    praveenkumar.dm | 2023-05-25 14:29:46 UTC | #9

    Thanks Declan,

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


    system | 2023-06-25 14:30:11 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: 20071