# Converting rule to action, how to deal with user.upn?

**URL:** <https://community.auth0.com/t/converting-rule-to-action-how-to-deal-with-user-upn/147315>\
**Category:** Get Help\
**Tags:** custom-webtasks, deprecations\
**Created:** [September 16, 2024, 7:00pm UTC](https://community.auth0.com/t/converting-rule-to-action-how-to-deal-with-user-upn/147315 "2024-09-16T19:00:34Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![daniel.ekbom](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/daniel.ekbom/32/60532_2.png) [@daniel.ekbom](https://community.auth0.com/u/daniel.ekbom)\
**Post date:** [September 16, 2024, 7:00pm UTC](https://community.auth0.com/t/converting-rule-to-action-how-to-deal-with-user-upn/147315/1 "2024-09-16T19:00:34Z")

</div>

Ready to post? 🔍 First, try searching for your answer.  
I am converting the following rule to action:

```auto
function (user, context, callback) {
  user.email = user.email || user.upn;
  callback(null, user, context);
}

```

I cannot figure out how to get the upn in an action.  
It is really important because sometimes I have noticed that email is missing for some users and then I need to use upn instead.

---

<div class="post-metadata">

**Author:** ![dawid.matuszczyk](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dawid.matuszczyk/32/74550_2.png) [@dawid.matuszczyk](https://community.auth0.com/u/dawid.matuszczyk)\
**Post date:** [September 30, 2024, 1:10pm UTC](https://community.auth0.com/t/converting-rule-to-action-how-to-deal-with-user-upn/147315/4 "2024-09-30T13:10:43Z")

</div>

Hi @daniel.ekbom

Welcome to the Auth0 Community!

One of the user had a similar problem and solved it with the usage of Management API with `getUser({ id: user.user_id })`

> **[Retrieve Users with the Get Users Endpoint](https://auth0.com/docs/manage-users/user-search/retrieve-users-with-get-users-endpoint)**
>
> Learn how to retrieve lists of users using the get\_users endpoint.

> [@Add the upn to event.user](https://community.auth0.com/t/add-the-upn-to-event-user/60839/4):
>
> I was able to get the upn field by using getUser({ id: user.user\_id }) from using the management api: [https://auth0.github.io/node-auth0/module-management.ManagementClient.html#getUser](https://auth0.github.io/node-auth0/module-management.ManagementClient.html#getUser)

Thanks  
Dawid

---

<div class="post-metadata">

**Author:** ![kreiswig](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/kreiswig/32/60978_2.png) [@kreiswig](https://community.auth0.com/u/kreiswig)\
**Post date:** [September 30, 2024, 7:32pm UTC](https://community.auth0.com/t/converting-rule-to-action-how-to-deal-with-user-upn/147315/5 "2024-09-30T19:32:55Z")

</div>

So the answer to this is to use the management api, yet Auth0 advocates against using the management API in actions. The following is from auth0’s migrate from rules to actions document.

[https://auth0.com/docs/customize/actions/migrate/migrate-from-rules-to-actions](https://auth0.com/docs/customize/actions/migrate/migrate-from-rules-to-actions)

_In general, we do not recommend calling the Management API from a high-traffic, critical path like Rules or Actions. Requests to all Auth0 APIs are rate limited, including calls from extensibility points, and calling an API for all logins could easily result in failed logins at high-traffic times_

Why isn’t the users upn available on the user object like it was in rules? Why wasn’t this listed in as a limitation in the actions limitations doc? [Actions Limitations](https://auth0.com/docs/customize/actions/limitations)

Will making management api calls in actions go against our M2M token auth quota?

---

<div class="post-metadata">

**Author:** ![kreiswig](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/kreiswig/32/60978_2.png) [@kreiswig](https://community.auth0.com/u/kreiswig)\
**Post date:** [September 30, 2024, 9:01pm UTC](https://community.auth0.com/t/converting-rule-to-action-how-to-deal-with-user-upn/147315/6 "2024-09-30T21:01:49Z")

</div>

Upon further investigation it looks like upn is now available on event.user? I tested by logging the users upn in a test action and it seems to be available, the types just need to be updated in the action editor, so good news!

Confirmation that this value is available and safe to use would be appreciated. Thanks

---

<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:** [October 14, 2024, 9:01pm UTC](https://community.auth0.com/t/converting-rule-to-action-how-to-deal-with-user-upn/147315/7 "2024-10-14T21:01:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dawid.matuszczyk](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dawid.matuszczyk/32/74550_2.png) [@dawid.matuszczyk](https://community.auth0.com/u/dawid.matuszczyk)\
**Post date:** [October 18, 2024, 2:14pm UTC](https://community.auth0.com/t/converting-rule-to-action-how-to-deal-with-user-upn/147315/8 "2024-10-18T14:14:40Z")

</div>

Hi @kreiswig and @daniel.ekbom

We’ve updated our Knowledge Solutions with a chapter about Adding Claims with Action in a similar fashion to how Rules worked. You can find it here → [Azure AD Integration not Providing the User Email](https://community.auth0.com/t/azure-ad-integration-not-providing-the-user-email/88924#p-236269-add-claims-using-actions-6)

Thanks  
Dawid
