# How to Determine Whether User Registration was from Universal Login or API in Actions?

**URL:** <https://community.auth0.com/t/how-to-determine-whether-user-registration-was-from-universal-login-or-api-in-actions/125379>\
**Category:** Get Help\
**Tags:** actions-management-api, management-api\
**Created:** [January 22, 2024, 7:01pm UTC](https://community.auth0.com/t/how-to-determine-whether-user-registration-was-from-universal-login-or-api-in-actions/125379 "2024-01-22T19:01:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sbm](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/sbm/32/49800_2.png) [@Sbm](https://community.auth0.com/u/Sbm)\
**Post date:** [January 22, 2024, 7:01pm UTC](https://community.auth0.com/t/how-to-determine-whether-user-registration-was-from-universal-login-or-api-in-actions/125379/1 "2024-01-22T19:01:08Z")

</div>

I would like to create a post user registration action that sends a password reset email only if the user is created from the Auth0 management API, not the universal login. Is there a way to determine the source of the action call?

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [January 22, 2024, 10:56pm UTC](https://community.auth0.com/t/how-to-determine-whether-user-registration-was-from-universal-login-or-api-in-actions/125379/3 "2024-01-22T22:56:40Z")

</div>

Hey there @Sbm welcome to the community!

> [@Sbm](#):
>
> Is there a way to determine the source of the action call?

The easiest way to go about this might be to just add a flag in user metadata when creating users via the API - This way you can check for the flag in the post registration action and implement any necessary logic:

Create User with `"api": true` flag in `user_metadata`

```auto
curl -L 'https://{}your_domain}.us.auth0.com/api/v2/users' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'Authorization: Bearer {management_api_access_token}' \
--data-raw '{"email":"test@example.com","user_metadata":{"api":true},"blocked":false,"email_verified":false,"app_metadata":{},"given_name":"foo","family_name":"bar","name":"foo","nickname":"foobar","connection":"Username-Password-Authentication","password":"xxxx","verify_email":false,"username":"foobar1"}'

```

Example post registration action:

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

  // Initialize management client
  const management = new ManagementClient({
    domain: event.secrets.domain,
    clientId: event.secrets.clientID,
    clientSecret: event.secrets.clientSecret,
  });

  // Define the user's ID
  const userId = event.user.user_id;

  if (event.user.user_metadata.api === true) {
    // Send a password reset email
    management.requestChangePasswordEmail({ user_id: userId }, (err) => {
      if (err) {
        console.error('Error sending password reset email:', err);
      } else {
        console.log('Password reset email sent successfully.');
      }
    });
  }
}

```

---

<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:** [February 5, 2024, 10:56pm UTC](https://community.auth0.com/t/how-to-determine-whether-user-registration-was-from-universal-login-or-api-in-actions/125379/4 "2024-02-05T22:56:53Z")

</div>

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