Problems getting historical adherence

I'm having some problems getting notifications for a historical adherence report. I'm sure it's something I'm doing wrong, but I can't figure it out. I've successfully setup presence notifications using similar code, so I know my connections to the notification handler are correct, but I'm not getting any responses back for the historical adherence report.

Can anybody take a look at my code and see if I'm doing something obviously wrong?

  • _userIds is a collection of user GUIDs

  • I do a get a successful response from PostWorkforcemanagementAdherenceHistoricalAsync() with an Id and query state of Processing. Obviously there's no DownloadUrl yet.

      WorkforceManagementApi wfmApi = new WorkforceManagementApi();
    
              _handler = new NotificationHandler();
    
              _handler.NotificationReceived += (data) =>
              {    if (data.GetType() == typeof(WfmHistoricalAdherenceCalculationsCompleteTopicWfmHistoricalAdherenceCalculationsCompleteNotice))`
                      {
                  }
              };
    
              WfmHistoricalAdherenceQueryForUsers body = new WfmHistoricalAdherenceQueryForUsers
              {
                  UserIds = _userIds,
                  StartDate = DateTime.Now.AddDays(-1),
                  EndDate = DateTime.Now,
                  TimeZone = "America/Chicago"
              };
    
              _response = await wfmApi.PostWorkforcemanagementAdherenceHistoricalAsync(body);
    
              _userIds.ForEach(u => _handler.AddSubscription($"v2.users.{u}.workforcemanagement.historicaladherencequery", typeof(WfmHistoricalAdherenceCalculationsCompleteTopicWfmHistoricalAdherenceCalculationsCompleteNotice)));

This probably isn't related, but it's much preferred to use the AddSubscriptions(...) method when subscribing to multiple topics. Each call to AddSubscription(...) makes an API request; using the plural version of the function will add all of the subscriptions in a single request.

To see if your or the SDK's code is discarding the message erroneously, you can hook up an event handler directly to the web socket using _handler.WebSocket.OnMessage += (sender, e) => { }. e.Data is the entire message body that you could log to the console.

To rule out an issue with your app entirely, you can listen for notifications using the Dev Tools Notification Tester and make the query using the Dev Tools API Explorer.

If you're able to rule out your app or the SDK as the cause (i.e. dev tools testing doesn't work either), please open a case with PureCloud Care to investigate further. They will be able to look into your specific data to see why a notification may not be raised.

Appreciate the feedback!

I had actually already changed my subscriptions to use AddSubscriptions instead, but thanks for that tip.

I hooked up the raw WebSocket OnMessage event and I'm getting the Websocket Heartbeat message but nothing else, even after quite a few minutes.

Just to be sure I'm thinking about this right, when I make a call for Historical Adherence, my WfmHistoricalAdherenceQueryForUsers object has a list of users in it. Then I need to subscribe to a notification topic for each of the users in that object that I queried for. Is that right?

I'll try out the Notification Tester and API Explorer method and let you know how that goes.

This could be a race condition because the query completes faster than you can subscribe to the topic. As a best practice, you should subscribe to a given topic before you intend to cause any activity on it.

That crossed my mind, too, so I flipped the code around to subscribe prior to making the call.

I played around with the API Explorer and Notification Tester and I'm still not having any luck. The API call gave me a "202 Accepted" but no notifications come in. I would expect, even if there isn't any valuable data for the users I'm requesting data for, I would still get a response through the notification mechanism.

I'll reach out to PureCloud Care to see if they can help me. Thanks.

1 Like

Just wanted to ask one more question around this one:

In PureCloud, I navigate Admin / Workforce Management / Performance / Historical Adherence. When I click on "Load Data" for any given day, I get a brief spinner, then an error that simply says "An error occured attempting to load".

Could this be related to the issue I'm getting when trying to retrieve this data over the API/Notifications?

Not sure, that's a generic error message that could be any number of things. I'd report that to Care as well.

I finally got this one figured out.

It turns out that instead of subscribing to notification topics that contain the user IDs of the users for which I am requesting data, I need to subscribe to a topic that contains my own user ID, or in my case the client ID of the client credentials I am using for make the call (since it's from a console application).

So, the topic I subscribe to is v2.users.{my client id}.workforcemanagement.historicaladherencequery. Just this one subscription.

This makes it simpler because I only have to subscribe to a single topic rather than a topic for each user for which I want data.

The documentation on this was not all clear to me that this is how it works, and even working with Pure Cloud Support we couldn't resolve the problem. It wasn't until one of my coworkers had an idea to try using my own user ID (rather than the ID of the user for which I'm requesting data) that we solved it.

1 Like

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