# Problems with getting userinfo from management API

**URL:** <https://community.auth0.com/t/problems-with-getting-userinfo-from-management-api/100786>\
**Category:** Get Help\
**Tags:** users, management-api\
**Created:** [February 18, 2023, 9:31am UTC](https://community.auth0.com/t/problems-with-getting-userinfo-from-management-api/100786 "2023-02-18T09:31:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mathiasm](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/mathiasm/32/44738_2.png) [@mathiasm](https://community.auth0.com/u/mathiasm)\
**Post date:** [February 18, 2023, 9:31am UTC](https://community.auth0.com/t/problems-with-getting-userinfo-from-management-api/100786/1 "2023-02-18T09:31:15Z")

</div>

Hi,

I’m having some problems synchronizing my auth0 userinfo with my local database. I have implemented this code;

```auto
userRouter.get("/sync", validateAccessToken, (req, res) => {
  var request = require("request");
  var usertoken;
  var options = { method: 'POST',
    url: 'https://MYDOMAN.eu.auth0.com/oauth/token',
    headers: { 'content-type': 'application/json' },
    body: '{"client_id":"myclienttoken","client_secret":"myclientsecret","audience":"https://MYDOMAIN.eu.auth0.com/api/v2/","grant_type":"client_credentials"}' };
  
  request(options, function (error, response, body) {
    if (error) throw new Error(error);
    usertoken = body;
    console.log(body);
  });
  var auth0options = {
    method: "GET",
    url: "https://MYDOMAIN.eu.auth0.com/api/v2/users",
    params: {id: 'email:"testuser"', search_engine: 'v3'},
    headers: {
      "content-type": "application/json",
      authorization: `Bearer` + usertoken.access_token,
    },
  };

  axios.request(auth0options).then(function (response) {
      console.log("RES DATA: ", response.data);
    })
    .catch(function (error) {
      console.error(error);
    });
  console.log("called");
  res.status(200).json("message");
});

```

But it dosen’t seem to work. I get the access token from this line:

> usertoken = body;

But I don’t get the userinfo when calling the auth0 api with that token. I’m using the audience from the Auth0 Management API ex:

> [https://MYDOMAIN.eu.auth0.com/api/v2/](https://mydomain.eu.auth0.com/api/v2/)

And not the audience from my own API, as I have read that’s the correct way:

[https://mydomain](https://mydomain)

Any ideas on what I’m doing wrong?

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [February 22, 2023, 2:43am UTC](https://community.auth0.com/t/problems-with-getting-userinfo-from-management-api/100786/3 "2023-02-22T02:43:46Z")

</div>

Hello @mathiasm welcome to the community!

> [@mathiasm](#):
>
> But I don’t get the userinfo when calling the auth0 api with that token. I’m using the audience from the Auth0 Management API ex:

Are you getting any error or error code that might be helpful in hinting at the issue? Does you M2M client in Auth0 have the right permissions(`read:users` and `read:user_idp_tokens`)? I’m not positive you can query by `id` - You may want to try `email` or `user_id`.

[https://auth0.com/docs/manage-users/user-search/user-search-query-syntax#searchable-fields](https://auth0.com/docs/manage-users/user-search/user-search-query-syntax#searchable-fields)

Keep us posted!

---

<div class="post-metadata">

**Author:** ![mathiasm](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/mathiasm/32/44738_2.png) [@mathiasm](https://community.auth0.com/u/mathiasm)\
**Post date:** [February 22, 2023, 7:53pm UTC](https://community.auth0.com/t/problems-with-getting-userinfo-from-management-api/100786/4 "2023-02-22T19:53:09Z")

</div>

Hi tyf.  
I found out that the main problem was that I was not waiting for reply about the mgmt token in my code, before calling the v2/users endpoint. That resulted in an error. After I made sure first to call that endpoint only after I received the mgmt key, it worked 🙂  
Now I just need to figure out why I’m not receiving all user data in my result.

Thank you for the help and great service.

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [February 22, 2023, 10:31pm UTC](https://community.auth0.com/t/problems-with-getting-userinfo-from-management-api/100786/5 "2023-02-22T22:31:55Z")

</div>

That’s great to hear! Thanks for following up with the community 🚀

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [March 9, 2023, 12:40am UTC](https://community.auth0.com/t/problems-with-getting-userinfo-from-management-api/100786/6 "2023-03-09T00:40:23Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
