I’m struggling to get my head around the documentation on how to implement the Management API. I saw a community link at How do i delete a user from auth0? which was helpful. There seems to be two options:
Using the Management API v2 Delete a user endpoint
For 1. above, is there more information and examples / tutorials on how to implement these? I assume some headers including tokens / secrets need to be included in requests.
For 2. above, is there somewhere in the documentation that refers to the Node Management API. I must of over looked it. I stumbled across this documentation as well https://node-auth0-docs.netlify.app/ - again, is this referred to in the core documentation somewhere?
I was able to implement the functionality I required after some trial and error / pot luck following reading the above community link. However, I feel like I can’t understand how to implement features of the Auth0 tool suite in a somewhat systematic way from looking at the documentation. Any help or guidance as to how to attack the documentation as it relates to the Management API or reference to other sources to help build up understanding of Auth0 more generally is greatly appreciated.
In a nutshell you can grab an access token by logging into your Auth0 Tenant and going to Applications > APIs > Auth0 Management API > “API Explorer” tab (the “Test” tab will also provide useful info in how to get an access token and how to use it).
Copy the provided token from the “API Explorer”. Then click on “Documentation” in the top right corner and select “Management API”. There’ll be a “SET API Token” button on the right hand side, click the button and paste the token in there.
You should now be able to click any of the endpoints from the left hand side and test them, also you can get the curl alternatives to execute on the command line/terminal.
This is very helpful and has started me on a good path - many thanks @SaqibHussain. Will delve deeper in the new day and drop a note if further questions.
The user_id I’ve pulled from a user in the dashboard and just used the number identifier (e.g. 658a36d431ed5183faa679f6). I noticed when using the full user_id (e.g. auth0|658a36d431ed5183faa679f6) in the API Explorer that the user_id which gets populated in the config url string is transformed so I’m assuming this might be a reason why I’m getting an invalid uri error.
I’ve tried using the Management API Token from the Explorer and that seems to be sufficient in a testing environment.
Any ideas on why this request might be failing?
Node Management API Client
This is more of a general question - when do you use the Management API as against the Node Management API Client? … Or should I only be using the Node Management API Client in development?
If I was to delete a user using the Management API via node.js I would do something like the below in a node script and execute the script on the terminal:
It looks like you’re trying to hit the Management API via a HTTP client (like Axios) but if you have installed the auth0 package from NPM locally then you don’t need to take this approach. Just use the local package.
If you do need to use the Management API over web then yes you would need to use a HTTP client of some sort, for delete user you would need to use the DELETE method against url like the below:
Many thanks @SaqibHussain and apologies for not responding earlier.
I think I have the Management API working. I’ve tried using the Management API via node.js and I get an “Grant type ‘client_credentials’ not allowed for the client.” A quick look at the documentation and unfortunately it seems like it will be another process of wrapping my head around the documentation / forum responses. This might be an issue for another thread when I can look at it more closely.
The new issue aside, I am still unclear on when I would use the vanilla Management API as against Node Management API Client? If you have any thoughts / comments / links on the topic that would be great.
As always, my thanks for your considered responses.
Edit: regarding the error I encountered above, I found a community post here which suggested a machine-to-machine application needed to be established. Once I did this and updated the relevant environment variables the delete action via the Node Management API Client worked. I will take a look at why this is the case but for now it has advanced where I was at.
In terms of when you would use the Management API v node.js version. I think it depends on your use case. For example, if you have a custom API backend or regular web application say written in .NET for example and your want to provide users with the ability to modify their user_metadata properties then this may lend itself nicely to calling the Management API directly.
Another scenario could be, if you have a backend service that runs on a schedule via some task scheduler, this may require an application that can execute on the command line and in this case the node.js offering might lend itself nicely here.
There may also be instances where the node.js npm package could execute over web if you have a node/express application and the Management API could be executed by a console app so it could just be a question of best for the job or even preference for one over the other.
The bottom line is, both options are available and you choose whichever fits best your use case.