What do I need to do with the Access Token?

I’ve been reading the management API documentation. I’ve been trying this simple thing, editing user metadata for a week now. Either there isn’t enough information or I’m stupid.

  1. How to I edit the metadata using node.js of the current user?

  2. I’ve seen one snippet of example code for node js and it uses axios, haven’t found a way to use the access token but i’ve got the following:

var options = {
method: ‘PATCH’,
url: ‘https://dev-0d4e6tjq.us.auth0.com/api/v2/users/{google-oauth2|1TESTTEST96jj4210TEST22808}’,
headers: {authorization: ‘Bearer ABCD’, ‘content-type’: ‘application/json’},
data: {
user_metadata: {hobby: ‘surfing’},
}
};

axios.request(options).then(function (response) {
console.log(response.data);
}).catch(function (error) {
console.error(error);
});

  1. What is “Bearer ABCD” in the above example? It seems to cause issues when I try to run that code: data: {
    statusCode: 400,
    error: ‘Bad Request’,
    message: ‘Bad HTTP authentication header format’,
    errorCode: ‘Bearer’
    }

That documentation is cracking me up. Showing just one example using node.js on the entire thing and using random libraries that are not even commonly used as if I’m supposed to know. Afterall I’m expected to pay for this service in the end.

If you are going to be basing your code on the example above with the axios request, you need to replace “ABCD” with the Management API access token.

Alternatively, you can use the Auth0 Node SDK here: https://auth0.github.io/node-auth0/index.html and do something like below

var ManagementClient = require('auth0').ManagementClient;

var management = new ManagementClient({
  token: '{YOUR_API_V2_TOKEN}',
  domain: '{YOUR_ACCOUNT}.auth0.com'
});

var params = { id: USER_ID };
var metadata = {
  foo: 'bar'
};

management.updateUserMetadata(params, metadata, function (err, user) {
  if (err) {
    // Handle error.
  }

  // Updated user.
  console.log(user);
});

Hope this helps!