# How to get username in get user script?

**URL:** <https://community.auth0.com/t/how-to-get-username-in-get-user-script/96826>\
**Category:** Get Help\
**Tags:** other, admin-management, missing-category, dashboard\
**Created:** [December 20, 2022, 4:02pm UTC](https://community.auth0.com/t/how-to-get-username-in-get-user-script/96826 "2022-12-20T16:02:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![anish.subedi](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/anish.subedi/32/33385_2.png) [@anish.subedi](https://community.auth0.com/u/anish.subedi)\
**Post date:** [December 20, 2022, 4:02pm UTC](https://community.auth0.com/t/how-to-get-username-in-get-user-script/96826/1 "2022-12-20T16:02:11Z")

</div>

Continuing the discussion from [Username does not work for login, only email works](https://community.auth0.com/t/username-does-not-work-for-login-only-email-works/57693):

I have two different fields in my database email and username. My api perform get user only through username not by email. How can get username in getuser script ? The documents says it must support username property but how to get it?

 ![image](https://global.discourse-cdn.com/auth0/original/3X/9/1/914f16ba04af7f388e5b98d090e20dd28a7cd5d6.png)

---

<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:** [December 20, 2022, 7:50pm UTC](https://community.auth0.com/t/how-to-get-username-in-get-user-script/96826/3 "2022-12-20T19:50:36Z")

</div>

Hi @anish.subedi,

Thanks for reaching out to the Auth0 Community!

I understand that you like to know how to get the username in the Get User script in your Custom Database.

It appears that the discussion already has a solution:

> [@Username does not work for custom mongodb connection](https://community.auth0.com/t/username-does-not-work-for-custom-mongodb-connection/57637/2):
>
> Hi @raalrwai , The sample template is assuming you are using emails only, not usernames. When you enable “Requires Username”, you will need to add additional logic to your Custom DB scripts to be able to handle the email parameter being passed as either an email or a username, and be able to find the user correctly with either. In both cases, it should return the same profile, including the username in said profile so it can be stored in Auth0 (for import mode). This is mentioned in the [docs](https://auth0.com/docs/connections/database/custom-db/templates/get-user): …

Please let me know if you have any trouble with the implementation or need further clarification.

Thanks,  
Rueben

---

<div class="post-metadata">

**Author:** ![anish.subedi](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/anish.subedi/32/33385_2.png) [@anish.subedi](https://community.auth0.com/u/anish.subedi)\
**Post date:** [December 21, 2022, 3:23am UTC](https://community.auth0.com/t/how-to-get-username-in-get-user-script/96826/4 "2022-12-21T03:23:45Z")

</div>

Thanks, @ruben.tiow for your prompt response.

Yes, additional logic is necessary to add in the get user script, but how to add that logic, auth0 has given us the template where only email can be used, and replacing and adding username parameter is not working here.  
`function getUser(email, callback) {

```auto
  // Send user identifier to external database API
  let options = {
    url: "https://example.com/api/search-users",
    body: {
      email: email
    }
  };`

```

Please please need more details on the implementation

---

<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:** [January 4, 2023, 3:24am UTC](https://community.auth0.com/t/how-to-get-username-in-get-user-script/96826/5 "2023-01-04T03:24:35Z")

</div>

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