createGuardianEnrollmentTicket results in undefined

After a lot of permutation/combinations, found a working solution…

const createGuardianEnrollmentTicketForUser = async (userId) => {
    const ManagementClient = require('auth0@2.27.0').ManagementClient;

    const managementClient = new ManagementClient({
      domain: 'MY_DOMAIN',
      clientId: "MY_CLIENT_ID",
      clientSecret: "MY_CLIENT_ID",
      scope: 'read:users update:users create:guardian_enrollment_tickets'
    });

    return new Promise(async (resolve, reject) => {
      if (managementClient && userId) {
        try {
          await managementClient.createGuardianEnrollmentTicket(
            {
              "user_id": userId,
              "send_mail": true
            },
            function (err, ticket) {
              if (err) {
                reject(err);
              }
              resolve(ticket);
            }
          );
        } catch (exp) {
          console.log('createGuardianEnrollmentTicketForUser exp:', exp);
          resolve([]);
        }
      } else {
        resolve([]);
      }
    });
  };

Hope the Auth0 people can update the official documentation with the following items:

  • body is required for this function, e.g. { "user_id": userId, "send_mail": true }
  • auth0@2.27.0 works

Thanks

1 Like