# Action is not adding role to user organization membership

**URL:** <https://community.auth0.com/t/action-is-not-adding-role-to-user-organization-membership/112499>\
**Category:** Get Help\
**Tags:** management-api, roles\
**Created:** [July 31, 2023, 3:16pm UTC](https://community.auth0.com/t/action-is-not-adding-role-to-user-organization-membership/112499 "2023-07-31T15:16:22Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![steffanie](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/steffanie/32/39762_2.png) [@steffanie](https://community.auth0.com/u/steffanie)\
**Post date:** [July 31, 2023, 3:16pm UTC](https://community.auth0.com/t/action-is-not-adding-role-to-user-organization-membership/112499/1 "2023-07-31T15:16:22Z")

</div>

Hello!

I have an Action to add a role to a user that is part of an organization, however when I check the member in the organization afterwards in the auth0 dashboard, they have no roles.

Eg after executing this post login action, I will still see no roles for the given user in the organization:

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

  const management = new ManagementClient({
    domain: event.secrets.domain,
    clientId: event.secrets.clientId,
    clientSecret: event.secrets.clientSecret,
    scope: "update:roles update:users create:organization_member_roles",
  });

  const params = { id: event.organization?.id, user_id: event.user.user_id };
  const data = { roles: [event.secrets.someRoleId] }

  await management.organizations.addMemberRoles(params, data, function (err) {
    if (err) {
        console.log('err', err)
      }
    });
}

```

Any ideas what I could be missing? Thanks in advance!

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [July 31, 2023, 6:52pm UTC](https://community.auth0.com/t/action-is-not-adding-role-to-user-organization-membership/112499/3 "2023-07-31T18:52:37Z")

</div>

Hi @steffanie,

After reviewing your code snippet, everything looks good.

Could you please let me know what kind of results you see when you run your Action script in the Action’s built-in debugger interface?

Thanks,  
Rueben

---

<div class="post-metadata">

**Author:** ![steffanie](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/steffanie/32/39762_2.png) [@steffanie](https://community.auth0.com/u/steffanie)\
**Post date:** [July 31, 2023, 7:00pm UTC](https://community.auth0.com/t/action-is-not-adding-role-to-user-organization-membership/112499/4 "2023-07-31T19:00:25Z")

</div>

Hi Rueben,

There are no errors when I run the Action with the test tool, but the response from addMemberRoles according to the docs is type undefined|Promise, if I console log the response it’s `undefined`.

---

<div class="post-metadata">

**Author:** ![steffanie](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/steffanie/32/39762_2.png) [@steffanie](https://community.auth0.com/u/steffanie)\
**Post date:** [July 31, 2023, 7:13pm UTC](https://community.auth0.com/t/action-is-not-adding-role-to-user-organization-membership/112499/5 "2023-07-31T19:13:55Z")

</div>

Silly me! I just checked the auth0 logs and saw that the client wasn’t granted the `create:organization_member_roles` scope, I just updated my app’s allowed scopes in the API dashboard and now it’s working 😅 Thank you!

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [August 1, 2023, 1:35am UTC](https://community.auth0.com/t/action-is-not-adding-role-to-user-organization-membership/112499/6 "2023-08-01T01:35:03Z")

</div>

Hi @steffanie,

Ah yes! Good catch on the client not being granted the necessary scopes!

I’m glad that everything is working now!

Please reach out if there’s anything else we can do to help.

Thanks,  
Rueben

---

<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:** [August 15, 2023, 1:35am UTC](https://community.auth0.com/t/action-is-not-adding-role-to-user-organization-membership/112499/7 "2023-08-15T01:35:24Z")

</div>

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