Legacy Dev Forum Posts

 View Only

Sign Up

Proper token passing / Pagination in async requests

  • 1.  Proper token passing / Pagination in async requests

    Posted 06-05-2025 19:07

    RomanSmoll | 2021-05-03 18:22:59 UTC | #1

    Hey there.

    I am working with NodeJs and AnalyticsAPI.

    I've noticed a following issue:

    I have an "entry sheet" which creates instances for logging in. I use a few API sets like Analytics etc...

    If i execute an API call that will generate me a JobID, and will try to pick it up in another file.js (that will login using the same clientId and clientSecret, I will get the bad request, invalid client.

    Should I get the token after 1st login and pass the token when creating instances in another file.js? If so, what is the safe way to store token so that it is not accessible from outside? (UPD) So, Somehow I have fixed it by not logging in in another file.js but just simply by creating :

    const platformClientCore = require('purecloud-platform-client-v2');

    const purecloudClient = platformClientCore.ApiClient.instance; const conversationApi = new platformClientCore.ConversationsApi(); const analyticsApi = new platformClientCore.AnalyticsApi();

    In the second file. Without passing it the token.. I have read articles and tutorials about oAuth but I still don't get why:

    • Create a new Instance-> no need for the token
    • Login with same ID and Secret -> code throws 400 -unathenticated user.

    ** and what is solution If I need to login again ans still profit from the same token anyway ?


    Second question is about the analytics API in particular

    • I am creating a job for async query for a period over 2 weeks.
    • I need all results.
    • However in the query constructor of developper tools I am obliged to pass the pageSize and PageNumber

    Will I get ALL the results in a bulk regardless of amount of pages there are and should I paginate when picking up the result?

    thank you :)


    anon11147534 | 2021-05-04 16:23:32 UTC | #2

    Hi,

    You must page through the responses to this API using the pageNumber value. The basic flow of paging through this API is:

    1. Send a request with pageNumber = 1
    2. While the response isn't {} , increment pageNumber and send a request.

    This API indicates no more records with an empty response ( {} ).


    RomanSmoll | 2021-05-04 16:39:57 UTC | #3

    Dear Ronan Thank you for your response.

    I am sure your answer is applicable to SYNC requests but what about async ones ? Are you sure it works for the async requests in the same way?

    I am talking for example

    > analyticsApi.getAnalyticsUsersDetailsJobResults

    There is not even such an entity as pageNumber in the request , only a Cursor which I have no idea how to work with

    This does not make any sense to send request asynchroniously for a large period if basically after that you still fetch the 1st page...at least to me

    Please help me figure out my confusion should I :

    do not put page I am searching for in my query for getting the job at the 1st place

    or

    I actually do keep it and still once I get the result , I paginate through?

    With best regards, Roman


    anon11147534 | 2021-05-05 15:36:19 UTC | #4

    Hi,

    Sorry, my answer only applied to sync requests.

    For async requests, the presence of a cursor indicates that more data is available. If a cursor is present, you can request further data by adding the cursor value in the query parameters.

    For example, if the cursor value Y3Vyc29yX3YyNDM0M was present in a result set the following request would be used to page through and request further data:

    /api/v2/analytics/conversations/details/jobs/6161b490-6dc2-4ac1-8da7-45763dc06859/results?cursor=Y3Vyc29yX3YyNDM0M

    You can page through until a response comes back without a cursor value.

    The pageSize can be used to control how many results are included in the result set. This can be a value between 1 and 10000, inclusive.


    RomanSmoll | 2021-05-04 17:06:31 UTC | #5

    Hey again , Ronan

    Thank you , this time you hit the bullseye :slight_smile:

    However before I mark it as an answer and close this thread,

    Imagine I need to create a report about every agent seeking to track his activity. (how much spent online, interacting, wrappingUp , pausing etc...)

    I am hesitating between the scenario as we discussed earlier or simply posting to create a report ( i fill figure out metrics later), download it and work from there.

    From your experience wouldn't it be easier this way ?

    With best, Roman


    anon11147534 | 2021-05-05 17:04:20 UTC | #6

    Hi,

    I'm honestly not sure which method is best. As long as both methods give you the required metrics the choice of API is totally up to you. The reporting section has been designed specifically for that purpose so it's probably better suited for creating agent reports.


    RomanSmoll | 2021-05-06 11:02:12 UTC | #7

    It actually is but to my understanding there is no way of modifying it. It seems you can't really create a custom report so I guess the coding is the best solution here.

    Ronan, I really appreciate your help on this one

    Thank you and take care. We can consider this thread to be officially closed.


    system | 2021-06-05 11:02:12 UTC | #8

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


    This post was migrated from the old Developer Forum.

    ref: 10801