New okta-sdk-nodejs

Hi All,

I checked an updated version of SDK and was little bit puzzled by methods client.listUsers and client.listUserGroups which both return some form of Collection. The problem is, I can’t get the number of items in the collection, or at least to check if it’s empty.

Is the only one method to do that is to attempt to iterate and calculate? Or am I missing something obvious?

Thanks in advance!

You might ask this at Okta Node Management SDK GH to see if there is a better way. The Okta /users API uses pagination, and the Okta Node Management SDK Collections encapsulates this for you by retrieving batches of users as you iterate through the collection. Once empty the next batch is retrieved from Okta until all users have been retrieved. To avoid iterating through each user you could do something like,

 var numUsers = 0;
 const orgUsersCollection = client.listUsers();
 console.log('\n\nCOUNT: ' + orgUsersCollection.currentItems.length + '\n\n');
 orgUsersCollection.each(user => {
    numUsers += orgUsersCollection.currentItems.length+1;
    orgUsersCollection.currentItems = [];
  .then(() => {
    console.log('All users have been listed')
  .catch( err => {

This could be bad practice however, as Node/JS is not one of my stronger languages.

1 Like

Thanks @erik , it’s something I was thinking about as a backup solution. I actually only needed to know if it’s empty or not, and I see some hints in your code snippet.

Appreciate your response!