Management API in actions


I saw some posts related to migrating code with Management API from rule to actions

I saw suggestion

const ManagementClient = require('auth0@2.17.0').ManagementClient;
const management = new ManagementClient({
    token: auth0.accessToken,
    domain: auth0.domain,

there is suggestions to replace with

exports.onExecutePostLogin = async (event, api) => {
  if (!event.user.email_verified) {
    	//send email again
    	var ManagementClient = require('auth0@2.19.0').ManagementClient;
    	var management = new ManagementClient({
    	    token: event.secrets.accessToken,
    	    domain: event.secrets.domain

But it does not work event.secrets.domain for example is empty
How can I do that ?


Hi @arnaud.mergey,

Thanks for reaching out to the Auth0 Comunity!

To make your custom Action work, I recommend that you add a secret for the domain and the token respectively.

Our documentation on Adding a Secret for Action goes into further detail:

After you’ve included these secrets, your custom action will work.

Please let me know how this works for you.

Thank you.

thanks for the reply.
It seems there is no way to get accessToken anymore like in rule, so the management api should be called like this

var management = new ManagementClient({
    	    domain: event.secrets.domain,
					clientId: event.secrets.clientId,
					clientSecret: event.secrets.clientId

do you confirm ?
thanks again

Hi @arnaud.mergey,

Thank you for your response.

Yes, that is correct, I can confirm.

Here is a FAQ community post going into detail on how to use the Management API in Actions:

Hoped this helps! Please let me know if there are any questions.

Thank you.

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