Important Update: Some Community URL Redirects are Under Maintenance. Learn More. .

cancel
Showing results for 
Search instead for 
Did you mean: 

Data return with Paged API - Javascript Transporter

matthancock
Contributor III

I am attempting to obtain paged API data with a Javascript transporter. I currently get the data but it is only the first page. The java script gets the data through callback functions and I am having trouble knowing where to put a loop for the pages as I only get the page total when at the end of the callbacks. 

I am trying to avoid using ?pagination=0 as the call could timeout.

 

1 REPLY 1

DougVaughan
Contributor II

I'm no JS dev, but I like to have some understanding of how the things I implement work.  The November update of the User Profile & Contacts Sync uses a paged JS transporter.  I suggest looking there.  

function requestUsersPage(pageNumber, pageSize)
{
    h.logInfo("requesting page " + pageNumber + " of users from Archer");
    var postBody = createPostBody(createODataFilter(),pageNumber,pageSize);
    // retrieve all the users from the Archer user store
    aapi.restCall('/platformapi/core/system/user', 'POST', postBody, true, (err,result)=> {
        if(err){
            h.logError(err);
            h.completeDataFeed(true);
        }
        else{
            h.logInfo("HTTP - OK response received");
            batchCount = result.length;
            for(var i=0;i<result.length;i++)
            {
                if(result[i]['IsSuccessful']){
                    h.logInfo("retrieved user " + result[i]['RequestedObject']['UserName']);
                    users.push(result[i].RequestedObject);
                }
            }
            if(batchCount == pageSize)
            {
                requestUsersPage(++pageNumber, pageSize)
            } 
            else
            {
                populateContactInfo();
            }
        }
    });
}