Problems with getting userinfo from management API


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

userRouter.get("/sync", validateAccessToken, (req, res) => {
  var request = require("request");
  var usertoken;
  var options = { method: 'POST',
    url: '',
    headers: { 'content-type': 'application/json' },
    body: '{"client_id":"myclienttoken","client_secret":"myclientsecret","audience":"","grant_type":"client_credentials"}' };
  request(options, function (error, response, body) {
    if (error) throw new Error(error);
    usertoken = body;
  var auth0options = {
    method: "GET",
    url: "",
    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: ",;
    .catch(function (error) {

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:

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


Any ideas on what I’m doing wrong?

Hello @mathiasm welcome to the community!

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.

Keep us posted!

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 :slight_smile:
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.

1 Like

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

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