Calling Auth0 API inside Actions

I have a Pre-registration action in place where I am calling the /api/v2/users-by-email API. I have to send the Bearer token to get the details but they actually expire in a certain time and it becomes a little hard to change every time it expires.
Is there a way to access Auth0 API in a different way? Or is there a totally different approach that can work for this use-case? I am new to Auth0 so any help is appreciated! Thanks in advance!

Hi @nikhil-varma,

Thanks for contacting the Auth0 Community!

I understand that it’s cumbersome to keep changing the Bearer token to use the Management API in your Actions whenever it reaches expiration.

Have you taken a look at our Community FAQ on how to use the Management API in Actions?

This should allow you to programmatically request the access token needed to use the Management API while keeping your token confidential.

You may also find the ManagementClient documentation useful:

Please let me know how this works for you.

Thank you.

Hey @rueben.tiow Apologies for the delay in responding. I tried doing this: Get Management API Access Tokens for Production to get access token and seems like it throws a 401 error despite all information being present right. Am I missing something? I have the M2M App set up since it’s the pre-requisite but it still doesn’t look like it’s working.

Hi @nikhil-varma,

Thank you for your reply!

First, could you please check that you have authorized your M2M application in the API settings?

You can check by going to your Auth0 Dashboard > Applications > APIs > Auth0 Management API > Machine to Machine Applications and making sure that your M2M application has enabled the Authorized switch. Please don’t forget to assign the permissions and save the changes.

Once that is done, you should be able to request the access token from the Management API.

Please let me know how that works for you.

Thank you.

@rueben.tiow Thanks!

I just checked and the applications are authorised with all permissions enabled. It still doesn’t seem to work and is throwing the same error. Am I missing something else? Thanks in advance!

Hi @nikhil-varma,

Before we continue, I have some clarifying questions.

First, are you able to follow How can I use the Management API in Actions? FAQ and get the Management API working with Actions?

Currently, it sounds like you are trying to get the Management API to work inside your application, could you please confirm?

If that is the case, you need to make a request similar to the following:

curl --request POST \
  --url '' \
  --header 'content-type: application/x-www-form-urlencoded' \
  --data grant_type=client_credentials \
  --data client_id=YOUR_CLIENT_ID \
  --data client_secret=YOUR_CLIENT_SECRET \
  --data audience=YOUR_API_IDENTIFIER

Please verify that you are using the correct values for your client_id, client_secret, and audience.

The audience should reference the Management API in the format

And the client_id and client_secret should match the authorized Machine-to-Machine application with ALL of the Management API permissions.

For example, you can use the M2M application on your Dashboard named API Explorer Application for these values.

I have tested this myself and was able to generate an Access Token to use with the Management API.

Please let me know if there’s anything else I can do to help.

Thank you.

1 Like

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