# Updating email\_verified from an action, error=change\_email script does not exist

**URL:** <https://community.auth0.com/t/updating-email-verified-from-an-action-error-change-email-script-does-not-exist/135878>\
**Category:** Get Help\
**Tags:** users, management-api\
**Created:** [June 7, 2024, 4:14am UTC](https://community.auth0.com/t/updating-email-verified-from-an-action-error-change-email-script-does-not-exist/135878 "2024-06-07T04:14:22Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![david.isackson](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/david.isackson/32/60163_2.png) [@david.isackson](https://community.auth0.com/u/david.isackson)\
**Post date:** [June 7, 2024, 4:14am UTC](https://community.auth0.com/t/updating-email-verified-from-an-action-error-change-email-script-does-not-exist/135878/1 "2024-06-07T04:14:22Z")

</div>

Hi,  
We use our own email verification process. During an Action I would like to be able to update the auth0 users email\_verified flag. I found other topics saying to use ManagementClient. I did this. The way it was coded in the post did not work. I had to added the API “audience” to the call. It now works but gets the error “ManagementApiError: **change\_email script does not exist** ”. I have search other posts but they all relate to Custom Database scripts, not actions. How do I update the email verify flag from an Action ?

This is the function within my Action-

```auto
attributeName = "email_verified";
attributeValue = true;

try {
    const ManagementClient = require('auth0').ManagementClient;
        
    let domain = event.request.hostname;
    let client_id = event.secrets.auth0Integration_client_id;
    let client_secret = event.secrets.auth0Integration_client_secret;
    let audience = event.secrets.auth0Integration_audience;

    debugLog("Domain:" + domain);
    debugLog("Client Id:" + client_id);    
    debugLog("Client Secret:" + client_secret);

    const management = new ManagementClient({
                domain: domain,
                clientId: client_id,
                clientSecret: client_secret,
                audience: audience       
    });

    const data = { [attributeName]: attributeValue };
    const params = { id : event.user.user_id};

    await management.users.update(params, data)

    return true;

  } catch (error) {
    console.error("Error in setUserRootAttribute:" + error);
    return false;
  }

```

thanks  
Dave

---

<div class="post-metadata">

**Author:** ![marcelina.barycka](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/marcelina.barycka/32/56162_2.png) [@marcelina.barycka](https://community.auth0.com/u/marcelina.barycka)\
**Post date:** [June 7, 2024, 8:32am UTC](https://community.auth0.com/t/updating-email-verified-from-an-action-error-change-email-script-does-not-exist/135878/2 "2024-06-07T08:32:19Z")

</div>

Hi there @david.isackson ,

Thank you for sharing - to help find out where the error may come from, I would like to understand the context this function runs in 🙂

The code shared is most likely a snippet of the bigger Action script, but I would like to make sure of that (?) What is the [flow](https://auth0.com/docs/customize/actions/flows-and-triggers) this function runs within?

---

<div class="post-metadata">

**Author:** ![david.isackson](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/david.isackson/32/60163_2.png) [@david.isackson](https://community.auth0.com/u/david.isackson)\
**Post date:** [June 8, 2024, 1:28am UTC](https://community.auth0.com/t/updating-email-verified-from-an-action-error-change-email-script-does-not-exist/135878/3 "2024-06-08T01:28:16Z")

</div>

Hi,

Thanks for the reply. Yes, this is indeed a function from within an Post-login action.

Business flow:

1. User signs up to our external system (via Salesforce)
2. The external system sends a confirmation email containing a hyperlink with an auth0 login URL containing a verification code.
3. The user clicks the link in the email. During the auth0 login, we run a Post Login action.
4. In this action, if the user is not currently email\_verified (ie. they are new) and the login URL contains a query string passing a verification code, we check that verification code with an external API call to our external system to validate the code. If the code is validated we activate the user in the external system.
5. If the user is activated in the external system, we also now want to set the email\_verified from “pending” to “verified” in auth0. This is the function posted above. This call fails with the " **change\_email script does not exist**" error. I just want to flag the user as now verified.

thanks  
Dave

---

<div class="post-metadata">

**Author:** ![marcelina.barycka](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/marcelina.barycka/32/56162_2.png) [@marcelina.barycka](https://community.auth0.com/u/marcelina.barycka)\
**Post date:** [June 10, 2024, 9:46am UTC](https://community.auth0.com/t/updating-email-verified-from-an-action-error-change-email-script-does-not-exist/135878/4 "2024-06-10T09:46:19Z")

</div>

Hi @david.isackson ,

Thank you very much for sharing the context.

To start debugging, I reduced the complexity of the code to a minimum to see if we could update the user property `email_verified = true` in a Login Action.

To this end, I wrote an action script that checks if the above property holds a false value (_replace with your own condition_) and, if so, updates the property to true.

```auto
exports.onExecutePostLogin = async (event, api) => {
  const ManagementClient = require('auth0').ManagementClient;
  if(!event.user.email_verified) {

    var management = new ManagementClient({
      domain: event.secrets.domain,
      clientId: event.secrets.clientId,
      clientSecret: event.secrets.clientSecret,
});
  
  await management.users.update({ id: event.user.user_id }, { email_verified: true });
  
  }

};

```

It successfully updates the property of a new user who logs in for the first time via the `Username-Password-Authentication` connection.

To figure out why it may have failed in your environment, I further checked the details of the Management API [endpoint responsible for updating user profiles](https://auth0.com/docs/api/management/v2/users/patch-users-by-id), and I found this:

 ![image](https://global.discourse-cdn.com/auth0/original/3X/b/2/b2770c4fa60b4606a68ffff95a28e23648baea69.png)

Is the connection you’re testing an Enterprise one?

---

<div class="post-metadata">

**Author:** ![david.isackson](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/david.isackson/32/60163_2.png) [@david.isackson](https://community.auth0.com/u/david.isackson)\
**Post date:** [June 11, 2024, 3:37am UTC](https://community.auth0.com/t/updating-email-verified-from-an-action-error-change-email-script-does-not-exist/135878/5 "2024-06-11T03:37:09Z")

</div>

Thank you Marcelina,

We use a Database connection because when the user is added to auth0 it must have previously been registered in Salesforce. In the Login script of the Custom Database, we call an API to confirm the username and password are correct in SF and then return some information. If valid, when create the user and update some metadata. The following Action called during this flow is the one that is failing.

return callback(null, {  
username: username,  
user\_id: salesforceUserId,  
email: email,  
name: userFullName,  
given\_name: firstName,  
family\_name: lastName,  
user\_metadata: {  
user\_language: languageCode,  
user\_locale: userLocale,  
user\_timezone: userTimeZone,  
user\_ui\_skin: userUiSkin,  
user\_country\_code: countryCode,  
},  
app\_metadata: {  
user\_id: userd,  
user\_type: userType,  
is\_family: isFamily,  
is\_terms\_consent: isTermsConsent,  
is\_privacy\_consent: isPrivacyConsent,  
},

---

<div class="post-metadata">

**Author:** ![peter.fernandez](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/peter.fernandez/32/45477_2.png) [@peter.fernandez](https://community.auth0.com/u/peter.fernandez)\
**Post date:** [June 11, 2024, 9:01am UTC](https://community.auth0.com/t/updating-email-verified-from-an-action-error-change-email-script-does-not-exist/135878/6 "2024-06-11T09:01:20Z")

</div>

> [@david.isackson](#):
>
> It now works but gets the error “ManagementApiError: **change\_email script does not exist** ”. I have search other posts but they all relate to Custom Database scripts, not actions. How do I update the email verify flag from an Action

Hi @david.isackson 👋

From the comments provided on this thread, it sounds like you’re using a _Custom Database Connection_ in Auth0. Correct? If so, then the error you’re seeing is likely due to the fact that - whilst you’ve created the _Login_ script in you’re _Custom Database Connection_ definition - you haven’t created a script for [_Change Email_](https://auth0.com/docs/authenticate/database-connections/custom-db/templates/change-email); the error in the Action context is actually a side-effect as a result of the missing script in the _Custom Database Connection_ definition.

If you don’t need to do anything outside of Auth0, then simply implement the email change script in the _Custom Database Connection_ definition as a no-op, as in:

```auto
function (email, newEmail, verified, callback) {
    // Return `true` value in callback to signal operation succeeded
    return callback(null, true);
}

```

Also, if you haven’t found it already, you may find our documentation on extensibility best practices to be helpful; see [here](https://auth0.com/docs/authenticate/database-connections/custom-db/custom-database-connections-scripts) for details.

Hope this helps 🕶

---

<div class="post-metadata">

**Author:** ![david.isackson](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/david.isackson/32/60163_2.png) [@david.isackson](https://community.auth0.com/u/david.isackson)\
**Post date:** [June 11, 2024, 11:18pm UTC](https://community.auth0.com/t/updating-email-verified-from-an-action-error-change-email-script-does-not-exist/135878/7 "2024-06-11T23:18:21Z")

</div>

Thank you Peter.

Let me try this and if it all works, I’ll mark it as the solution.

thanks  
Dave

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [June 25, 2024, 11:18pm UTC](https://community.auth0.com/t/updating-email-verified-from-an-action-error-change-email-script-does-not-exist/135878/8 "2024-06-25T23:18:38Z")

</div>

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