Legacy Dev Forum Posts

 View Only

Sign Up

Adherence Historical Exception Report

  • 1.  Adherence Historical Exception Report

    Posted 06-05-2025 18:22

    asharma | 2022-04-20 10:13:31 UTC | #1

    Hi, with the historical adherence report requiring client side authentication (implicit or code auth) , I am interested to know what patterns people are using if they need to run this extraction automatically for ingestion into a data lake.


    Eos_Rios | 2022-04-20 14:42:51 UTC | #2

    We use the DotNet Library and an OAuth account to open a socket listener;

    NotificationHandler notificationHandler = new NotificationHandler(c); notificationHandler.NotificationReceived += NotificationReceived;

    notificationHandler.AddSubscription( $"v2.users.{Client.ClientId}.workforcemanagement.historicaladherencequery" , typeof( WfmHistoricalAdherenceResponse ) );

    Then we run each of the reports we want;

    string timeZone = BusinessUnits[ManagementUnits[MUID]]; WfmHistoricalAdherenceQuery query = new WfmHistoricalAdherenceQuery(dateRange.Begins, dateRange.Ends.Date.AddDays(1), timeZone); WfmHistoricalAdherenceResponse response = wfmApi.PostWorkforcemanagementManagementunitHistoricaladherencequery(MUID, query);

    And the handler "receives" the results and parses/redirects the output.


    asharma | 2022-04-20 21:24:35 UTC | #3

    Thanks. How do you manage the credentails part? My understanding is that to use code auth, we need to do something like below:

    clientid = 'xxxxxxxxxxxxxxx' redirecturi = 'http://127.0.0.1:5000' authorizationcodereq = { "responsetype": "code", "clientid": clientid, "redirecturi": redirecturi } baseurl = 'https://login.mypurecloud.com.au/oauth/authorize?' r = requests.get(baseurl + urlencode(authorizationcodereq), allowredirects=False) url = r'https://login.mypurecloud.com.au' + r.headers.get('location') webbrowser.open(url)

    This pops the browser and returns the code to the redirect url after which we can then do the following:

    authclient, authtokeninfo = PureCloudPlatformClientV2.apiclient.ApiClient().getcodeauthorizationtoken( 'xxxxxxxxxx', 'yyyyyyyyy', authcode, redirect_uri)

    If we are running the extraction server side, it wont work since there is no browser that is popped to do the auth.


    Eos_Rios | 2022-04-20 22:49:46 UTC | #4

    With an OAuth client it's just;

    AuthTokenInfo accessTokenInfo = Configuration.Default.ApiClient.PostToken( ClientId , ClientSecret ); Configuration.Default.AccessToken = accessTokenInfo.AccessToken;

    And the library does everything else, human account not required for that API>


    asharma | 2022-04-21 00:48:21 UTC | #5

    Got it!!! I had no idea that we could listen for notifications on a client id and all the examples i could find pointed to getting the user id. I reworked my code as follows which works fine:

    apiclient = PureCloudPlatformClientV2.apiclient.ApiClient().getclientcredentialstoken( GENESYSCLOUDCLIENTID, GENESYSCLOUDCLIENTSECRET) notificationinstance = PureCloudPlatformClientV2.NotificationsApi(apiclient) response = createnotificationchannel(notificationinstance) uri = response.connecturi channelid = response.id body = [ {"id": f"v2.users.{GENESYSCLOUDCLIENTID}.workforcemanagement.historicaladherencequery"} ] try: notificationinstance.putnotificationschannelsubscriptions(channelid, body) except ApiException as e: print("Exception when calling notification api")

    timer = threading.Timer(5, getadherencequery, args=[apiclient]) timer.start() asyncio.run(listen(uri, channelid))

    Thanks


    system | 2022-05-22 00:21:56 UTC | #6

    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: 14380