1

Code snippet:

async getUsersByEmail(value) {
    try {
      return await Promise.all([
        oktaClient.listUsers({
          search: value,
        }),
      ]).then((values) => {
        console.log(values);
      });
    } catch (e) {
      throw Error('Cannot get the users: ' + e);
    }
  }

Response:

[
   Collection {
     nextUri: "http://test-admin.okta.com/api/v1/users?search=profile.email%20eq%20'test%40gmail.com'%20",
     client: Client {
       requestExecutor: [DefaultRequestExecutor],
       authorizationMode: 'SSWS',
       baseUrl: 'http://test-admin.okta.com',
       apiToken: 'dhdkjaskjassad',
       http: [Http]
     },
     factory: ModelFactory { Ctor: [class User extends Resource] },
     currentItems: [],
     request: undefined
   }
 ]

I am unable to get response array while trying to use already available okta-sdk-nodejs's listUsers method. Though, I am getting correct response with same request parameters while trying to run with Postman.

OKTA API Doc Link

OKTA SDK node.js Link (Go to Search for Users section)

I am using the following method ->

client.listUsers({
  search: 'profile.email eq "test@gmail.com"'
}).each(user => {
  console.log('User matches search:', user);
});
James Z
  • 12,209
  • 10
  • 24
  • 44

1 Answers1

2

I was able to resolve this issue after making slight change in my code.

Updated code:

   async getUsersByEmail(query) {
    try {
      let users = [];
      const response = await oktaClient.listUsers({
        search: query,
      });
      await response
        .each((user) => {
          users.push(user);
        })
        .catch((err) => {
          console.log(`Error while getting usersByEmail ` + err);
        });
      console.log(`Users data: ` + users);
      return users;
    } catch (e) {
      throw Error(`Cannot get usersByEmail: ` + e);
    }
  }