2

The docs for intercom-node, https://github.com/intercom/intercom-node, say that I can access my users data with the client.users.list or client.users.listBy or client.users.find.

The problem is I am only getting 50 users in the body of the response object (ie resp.body.users.length is 50) and I need all the users. Does anyone know how to query the API to get all the users from the intercom.io app?

var Intercom = require('intercom-client')
var client = new Intercom.Client('<APP ID>', '<API KEY>')

client.users.list( function(err, resp) { 
    console.log(resp.body.users.length)
})
currenthandle
  • 1,038
  • 2
  • 17
  • 34
  • Sounds like they paginate / limit by default. This might be helpful to you - https://github.com/intercom/intercom-node#pagination – dvlsg Jun 02 '16 at 23:57

1 Answers1

1

With the current library version 2.11.2 the next page can be retrieved by specifying the page number and using .listBy or using the pagination object https://github.com/intercom/intercom-node#pagination after using .list (demo code below)

var Intercom = require('intercom-client');
var client = new Intercom.Client({ token: TOKEN });

client.users.listBy({page: 1}, printDetails);
client.users.listBy({page: 2}, printDetails);

client.users.list(printDetailsAndGetNextPage);
client.users.listBy({page: 1}, printDetailsAndGetNextPage);

function printDetails(d){
    var output = d.body;
    console.log("Page: " + output.pages.page + " out of " + output.pages.total_pages);
}

function printDetailsAndGetNextPage(d){
    var output = d.body;
    console.log("Page: " + output.pages.page + " out of " + output.pages.total_pages);
    if(output.pages.page < output.pages.total_pages) {
        console.log("Getting next page...");
        client.nextPage(output.pages, printDetails);
    }
    else {
        console.log("No more pages left");
    }
}

demo

thewheat
  • 988
  • 7
  • 13