# Access Denied when trying to use api.user.setAppMetadata

**URL:** <https://community.auth0.com/t/access-denied-when-trying-to-use-api-user-setappmetadata/102758>\
**Category:** Get Help\
**Tags:** actions-management-api, management-api\
**Created:** [March 17, 2023, 12:32am UTC](https://community.auth0.com/t/access-denied-when-trying-to-use-api-user-setappmetadata/102758 "2023-03-17T00:32:54Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jrmcpeek](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jrmcpeek/32/41344_2.png) [@jrmcpeek](https://community.auth0.com/u/jrmcpeek)\
**Post date:** [March 17, 2023, 12:32am UTC](https://community.auth0.com/t/access-denied-when-trying-to-use-api-user-setappmetadata/102758/1 "2023-03-17T00:32:54Z")

</div>

Following: [Manage User Metadata with the post-login Action Trigger](https://auth0.com/docs/manage-users/user-accounts/metadata/manage-user-metadata)

We have an action that runs at post-login.

Everything works as expected except a call to `api.user.setAppMetadata("key", "value");` causes the following error:

```json
    "error": {
      "message": "user update failed: %!w(<nil>)",
      "oauthError": "access_denied",
      "type": "oauth-authorization"
    },

```

Removing the call to `api.user.setAppMetadata("key", "value");` and redeploying the action causes the issue to go away.

Is there a specific permission necessary for this? I could not find anything in the documentation.

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [March 23, 2023, 2:58pm UTC](https://community.auth0.com/t/access-denied-when-trying-to-use-api-user-setappmetadata/102758/3 "2023-03-23T14:58:55Z")

</div>

Hi @jrmcpeek,

I can help you with this. I’d like to try and reproduce the error. Can you please provide the code you are using in the Action, and any other info unique to your setup? Thank you!

---

<div class="post-metadata">

**Author:** ![jrmcpeek](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jrmcpeek/32/41344_2.png) [@jrmcpeek](https://community.auth0.com/u/jrmcpeek)\
**Post date:** [March 23, 2023, 3:14pm UTC](https://community.auth0.com/t/access-denied-when-trying-to-use-api-user-setappmetadata/102758/4 "2023-03-23T15:14:06Z")

</div>

The following should cause it, as part of a post-login Auth0 Action:

```auto
exports.onExecutePostLogin = async (event, api) => {
  /* some long-running action on an external service */
  const output = "test@email.com";

  api.user.setAppMetadata("email", output);
}

```

No special or unique settings for the tenant that I am aware of. Happens both in a free-tier dev tenant as well as a paid production tenant.

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [March 23, 2023, 3:31pm UTC](https://community.auth0.com/t/access-denied-when-trying-to-use-api-user-setappmetadata/102758/5 "2023-03-23T15:31:45Z")

</div>

Thanks for the added info.

It looks like `email` is a protected field in the `app_metadata` property. All of the restricted fields are listed here: [Metadata Field Names and Data Types](https://auth0.com/docs/manage-users/user-accounts/metadata/metadata-fields-data#restrictions)

Let me know if you have any questions!

---

<div class="post-metadata">

**Author:** ![jrmcpeek](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jrmcpeek/32/41344_2.png) [@jrmcpeek](https://community.auth0.com/u/jrmcpeek)\
**Post date:** [March 23, 2023, 3:40pm UTC](https://community.auth0.com/t/access-denied-when-trying-to-use-api-user-setappmetadata/102758/6 "2023-03-23T15:40:02Z")

</div>

Easy enough to fix. It would be good if the error message was de-mangled to provide that information in the log 😊

Thanks!

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [March 23, 2023, 3:40pm UTC](https://community.auth0.com/t/access-denied-when-trying-to-use-api-user-setappmetadata/102758/7 "2023-03-23T15:40:55Z")

</div>

I couldn’t agree more! I am going to let our engineering team know about that error. Thanks for your patience.

---

<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:** [April 10, 2023, 3:51pm UTC](https://community.auth0.com/t/access-denied-when-trying-to-use-api-user-setappmetadata/102758/9 "2023-04-10T15:51:58Z")

</div>

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