# Signup via api: setting user metadata first name and last name

**URL:** <https://community.auth0.com/t/signup-via-api-setting-user-metadata-first-name-and-last-name/87814>\
**Category:** Get Help\
**Tags:** wordpress-auth0, api, auth0\
**Created:** [July 28, 2022, 12:21pm UTC](https://community.auth0.com/t/signup-via-api-setting-user-metadata-first-name-and-last-name/87814 "2022-07-28T12:21:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![admin37](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/admin37/32/12951_2.png) [@admin37](https://community.auth0.com/u/admin37)\
**Post date:** [July 28, 2022, 12:21pm UTC](https://community.auth0.com/t/signup-via-api-setting-user-metadata-first-name-and-last-name/87814/1 "2022-07-28T12:21:54Z")

</div>

Hi there,

I’m using Auth0 + wordpress plugin to authenticate. This works fine.

1. 

For signups I use the api via http post request. I want to add user\_metadata to the signup (first name and last name)…can anyone give me a hint how to create the post-call correctly to include user\_metadata for firstname and lastname?

1. When logging in the first time I want auth0 to hand over the user\_metadata (first and last name ) to wordpress so the names are set correctly. How to I have to modify the rules so auth0 also sets first name and last name when creating the wordpress user during the first login?

Thanks!  
Philipp

---

<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, 2022, 10:34pm UTC](https://community.auth0.com/t/signup-via-api-setting-user-metadata-first-name-and-last-name/87814/3 "2022-08-01T22:34:09Z")

</div>

Hi @admin37,

Thanks for reaching out to the Auth0 Community!

I understand you have questions about setting the user’s user\_metadata (first name and last name) when creating users.

1. When using the Management API [create a user’s](https://auth0.com/docs/api/management/v2#!/Users/post_users) endpoint, you can specify the `user_metadata` properties in the request body:

```auto
{
  "email": "john.doe@gmail.com",
  "connection": "Initial-Connection",
  "password": "secret",
  "user_metadata": {
      "first_name": "John",
      "last_name": "Doe "
  }
}

```

1. There is an option to make a WordPress API call within an Auth0 Action to pass the user\_metadata values. Moreover, you can check for the user’s `logins_count` to allow this to only happen for the user’s first successful login.

For example:

```auto
exports.onExecutePostLogin = async (event, api) => {
  if (event.stats.logins_count === 1) {
    var firstName = event.user.user_metadata.first_name
    var lastName = event.user.user_metadata.last_name
    //YOUR LOGIC HERE
  }
};

```

I hope this helps!

Please let me know how this works for you.

Thank you.

---

<div class="post-metadata">

**Author:** ![admin37](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/admin37/32/12951_2.png) [@admin37](https://community.auth0.com/u/admin37)\
**Post date:** [August 23, 2022, 1:32pm UTC](https://community.auth0.com/t/signup-via-api-setting-user-metadata-first-name-and-last-name/87814/5 "2022-08-23T13:32:20Z")

</div>

Hi @ [rueben.tiow](https://community.auth0.com/u/rueben.tiow),

Could you please iterate on the second step. We added the method onExecutePostLogin as Custom Action into Actions / Login.

Where your script says //YOUR LOGIC HERE do we have to call the WordPress API and write the users metadata to WP? At this point we don’t even know the WP userid to call an update on the user model, right? Also there is no way to search for a user by email through WP API?

Is there already an active connection through the Auth0 WordPress Plugin? Or do we have to call the API as regular from an outside script?

Thanks

---

<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 29, 2022, 4:43pm UTC](https://community.auth0.com/t/signup-via-api-setting-user-metadata-first-name-and-last-name/87814/6 "2022-08-29T16:43:18Z")

</div>

Hi @admin37,

Thank you for your reply.

> [@admin37](#):
>
> Where your script says //YOUR LOGIC HERE do we have to call the WordPress API and write the users metadata to WP?

Yes, this would be the section where you call the WP API to write the user’s metadata to WP by passing the `firstName` and `lastName` variables in the request.

> [@admin37](#):
>
> At this point we don’t even know the WP userid to call an update on the user model, right? Also there is no way to search for a user by email through WP API?

I just reviewed the [WP API Documentation](https://developer.wordpress.org/rest-api/reference/users/) and agree that there is no way to search for a user by email.

That being said, as a workaround, I recommend storing the user\_id in the user\_metadata as part of Step 1. This way, you can make the POST request to update the user in Step 2.

> [@admin37](#):
>
> Is there already an active connection through the Auth0 WordPress Plugin? Or do we have to call the API as regular from an outside script?

I believe so. You should be able to determine this by checking where the Connection name of where the user belongs on the [Auth0 Dashboard \> User Management \> Users](https://manage.auth0.com/#/users) page.

I hope this answers your questions. Please let me know if there’s anything else I can do to help.

Thank you.

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [December 22, 2022, 10:57am UTC](https://community.auth0.com/t/signup-via-api-setting-user-metadata-first-name-and-last-name/87814/7 "2022-12-22T10:57:38Z")

</div>


