Legacy Dev Forum Posts

 View Only

Sign Up

Help with PostUsersAggregatesQuery

  • 1.  Help with PostUsersAggregatesQuery

    Posted 06-05-2025 18:04

    canderson | 2016-08-03 14:31:46 UTC | #1

    I'm having problems getting this working in the Users API. I haven't been able to find a full, working example anywhere, including the unit tests in the GitHub repo ([url]https://github.com/MyPureCloud/purecloud_api_sdk_csharp/blob/master/build/src/ININ.PureCloudApi.Test/Api/UsersApiTests.cs[/url]).

    If I do what is described in the documentation ([url]https://developer.mypurecloud.com/api/rest/client-libraries/csharp/latest/UsersApi.html#postusersaggregatesquery[/url]) then I get "Instantiation of [simple type, class com.inin.analytics.api.v6.aggregates.AggregationQueryV6] value failed: interval is required".

    If I put in an interval, I get "at least one dimension must be specified".

    If I further put in a dimension, I continue to get the same error as before. Here's the code I'm trying:

    [code] var apiInstance = new UsersApi();

    List<AnalyticsQueryPredicate> predicates = new List<AnalyticsQueryPredicate>(); predicates.Add(new AnalyticsQueryPredicate( AnalyticsQueryPredicate.TypeEnum.Dimension, AnalyticsQueryPredicate.DimensionEnum.Userid, Value: userId, _Operator: AnalyticsQueryPredicate.OperatorEnum.Matches));

    var body = new AggregationQuery(); body.Interval = FormatDatesForQuery(new DateTime(2016, 6, 1), DateTime.Now);

    body.Filter = new AnalyticsQueryFilter(AnalyticsQueryFilter.TypeEnum.And, Predicates: predicates);

    PresenceQueryResponse result = apiInstance.PostUsersAggregatesQuery(body); [/code]

    The same pattern for querying is used on many different calls so I'd really like to figure out how these work.

    Can anybody help?


    tim.smith | 2016-08-03 17:11:14 UTC | #2

    I've spent some time working with the analytics dev team to work through this and have created API-1806 to address several documentation issues with this resource. The caveats are:

    • You must specify user IDs in your filter predicate
    • You must group by userId (this is probably what was causing your error; the text is incorrect)

    Here's my test code that creates a successful query:

    var usersApi = new UsersApi(); var body = new AggregationQuery(); body.Interval = DateTime.Today.AddDays(-7).ToUniversalTime().ToString("s", CultureInfo.InvariantCulture) + "/" + DateTime.Today.AddDays(1).ToUniversalTime().ToString("s", CultureInfo.InvariantCulture); body.Filter = new AnalyticsQueryFilter(Type: AnalyticsQueryFilter.TypeEnum.Or, Predicates: new List<AnalyticsQueryPredicate> { new AnalyticsQueryPredicate(Dimension: AnalyticsQueryPredicate.DimensionEnum.Userid, Value: _me.Id) }); body.GroupBy = new List<AggregationQuery.GroupByEnum> {AggregationQuery.GroupByEnum.Userid};

    var result = usersApi.PostUsersAggregatesQuery(body);


    canderson | 2016-08-03 17:53:17 UTC | #3

    Thank you for the response. The Group By was certainly missing, and you're right that the error text was incorrect. Hopefully that can be fixed.

    The other thing that was different between my code and yours was the date range. My sample code was running all the way back to 6/1/2016. When I run it with that date range I get this error: [b]"Supplied granularity PT5488397S must be a multiple of PT1800S"[/b]

    When I change it to just do the last seven days (but format the dates the same way I have for other successful queries) I get: [b]"Granularity ( P1W ) must evenly divide the specified interval span, accounting for the timezone ( 2016-07-27T12:34:12.000Z/2016-08-03T12:34:12.000Z )"[/b]. Plus, the date format in the error message isn't the same as the date format in the notes for the Interval property. The notes don't show milliseconds or the trailing "Z", plus it appears they actually aren't required.

    The error message isn't clear on what "P1W" is, or any of the other codes (PT5488397S and PT1800S).

    The only way I was able to actually get it worked was to use DateTime.Today, like in your example, instead of DateTime.Now.

    I just need a bit of clarification on how the date ranges need to be configured to be successful.

    Thanks.


    tim.smith | 2016-08-03 18:00:18 UTC | #4

    The dates must adhere to the ISO 8601 spec. The PT designation is a duration with P meaning "period" and T meaning "time", followed by a number, and S meaning "seconds". So PT1800S can be read as "a period of time of 1800 seconds".


    system | 2017-08-28 19:25:50 UTC | #5


    This post was migrated from the old Developer Forum.

    ref: 210