Auth0 Home Blog Docs

User Search Query Not Working In NodeJS


#1

I have a Javascript app that is utilizing the Auth0 library. I have logged in one user with Twitter and two with LinkedIn and one with Auth0 for a total of 4 user records. I have a user login with LinkedIn and then we get a response back from the callback that looks like this:

Object {
  "family_name": "Smith",
  "given_name": "John",
  "name": "John Smith",
  "nickname": "john.a.smith",
  "picture": "https://media.licdn.com/dms/image/C4E03AQG-Cn-ouWQlpQ/profile-displayphoto-shrink_100_100/0?e=1537401600&v=beta&t=gIg442j35l2A6gdatgi_B523r3hJFFQ5KjbuZDZtqU",
  "sub": "linkedin|QJn-UJxjUx",
  "updated_at": "2018-07-17T07:27:13.041Z",
}

I want to then retrieve the details of that account so I use the management API to make a search query. My query looks like this:

    const userSearchResponse = await fetch(`${privateKeys.auth0.domain}/api/v2/users`, {
      method: 'GET',
      headers: {
        qs: { q: 'identities.user_id⁠⁠⁠⁠.raw:"QJn-UJxjUx"', search_engine: 'v2' },
        authorization: `Bearer ${privateKeys.auth0.managementToken}`
      }
    });

    const userSearchParsed = await userSearchResponse.json();

    this.extractLinkedInData(userSearchParsed);

However, when I make this search query it returns all 4 records every time. I have tried changing the q param to be

'nickname:"john.a.smith"''
'nickname.raw:"john.a.smith"''

And none of these work. I’m getting every record back (from Twitter, Auth0, and LinkedIn). Has anyone had any success using the search query with JS? Thanks in advance!


#2

So I found an issue while using Postman to test this. When you add search_engine v2 or v3 you get an error response that says that search engine v2 and v3 are not valid options. Additionally, I had to put the query in the URL, I could not add them as headers as described in the example. So by URL encoding the nickname search I was able to get the results that I needed. Hopefully, this helps someone in the future. Hopefully, the docs get updated soon as well or the API gets fixed.