# How to change user fields with API

**URL:** https://meta.discourse.org/t/how-to-change-user-fields-with-api/147999
**Category:** Development
**Tags:** rest-api
**Created:** [April 14, 2020, 7:16pm UTC](https://meta.discourse.org/t/how-to-change-user-fields-with-api/147999 "2020-04-14T19:16:27Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![pnoeric](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pnoeric/32/177144_2.png) [@pnoeric](https://meta.discourse.org/u/pnoeric)
#### Post date: [April 14, 2020, 7:16pm UTC](https://meta.discourse.org/t/how-to-change-user-fields-with-api/147999/1 "2020-04-14T19:16:28Z")

</div>

## (Edit: see 2nd post for solution: how to change user fields with API)

@sam, you mentioned (in a post in a topic now closed) with regards to someone who wanted to use the API to update a custom field in a user record: “the field needs to be whitelisted can you add it to `/admin/customize/user_fields` or is this field meant to be completely hidden from users?”

Two quick questions

1. What is `/admin/customize/` endpoint?
2. How do you “whitelist” a field? (What does that mean-- whitelist it so the API can access it, somehow?!)

I’ve searched for the answers for both of these without luck, hopefully you (or someone else who knows) can help.

BTW my ultimate goal seems simple: I want to be able to set/get the value of a custom user field with the API. Yet I’m finding it’s incredibly difficult to get a clear answer about how to do this. ☹

So far I’ve figured out:

1. You can sorta pass custom fields via SSO, but that’s not the API
2. The custom fields appear to be referenced only by number, not by name, when the front-end calls the API (via watching the XHR request) - obviously that makes a big difference if I’m looking for it by name but it’s really `users[2]`

As you can see, it’s non-obvious 😉 and I figure the ‘get’ is easier since it will be part of the user record (which I can get now with the API), but I can’t confirm until I can ‘set’ it with the API.

Anyhow… once I finally figure this out, how can I contribute that knowledge back in a way that will help the next person trying to do this?

---

<div class="post-metadata">

### Author: ![blake](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/blake/32/157322_2.png) [@blake](https://meta.discourse.org/u/blake)
#### Post date: [April 14, 2020, 9:33pm UTC](https://meta.discourse.org/t/how-to-change-user-fields-with-api/147999/2 "2020-04-14T21:33:11Z")

</div>

You can create a user with custom fields via the API by passing in `user_fields[1]` like this:

```plaintext
curl -i -sS -X POST "http://localhost:3000/users" \
-H "Content-Type: multipart/form-data;" \
-H "Api-Key: d19b5a38ed13745f4c5..." \
-H "Api-Username: system" \
-F "name=cbbc7188c201b59ebc06" \
-F "username=cbbc7188c201b59ebc06" \
-F "email=cbbc7188c201b59ebc06@example.com" \
-F "password=b6629ed30b4bc3de32ce452d171540b0" \
-F "active=true" \
-F "approved=true" \
-F "user_fields[1]=a874d830b60" \
-F "user_fields[2]=732418b131b"

```

 ![image](https://global.discourse-cdn.com/meta/original/3X/7/e/7e574b3a09d83ec3a5c4feff321c93504e5b3325.png)

And you can update them by sending a PUT request to `/u/<username>.json`

 ![image](https://global.discourse-cdn.com/meta/original/3X/4/b/4b36e80e484716d3038479083c846771807413b2.png)

---

<div class="post-metadata">

### Author: ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)
#### Post date: [April 14, 2020, 10:20pm UTC](https://meta.discourse.org/t/how-to-change-user-fields-with-api/147999/3 "2020-04-14T22:20:59Z")

</div>

> [@pnoeric](#):
>
> What is `/admin/customize/` endpoint?

`/admin/customize/user_fields` is a UI page where the custom user fields are configured.

---

<div class="post-metadata">

### Author: ![pnoeric](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pnoeric/32/177144_2.png) [@pnoeric](https://meta.discourse.org/u/pnoeric)
#### Post date: [April 15, 2020, 11:15am UTC](https://meta.discourse.org/t/how-to-change-user-fields-with-api/147999/4 "2020-04-15T11:15:46Z")

</div>

> [@blake](#):
>
> You can create a user with custom fields via the API by passing in `user_fields[1]` like this:

Thank you for all of this help! FWIW I’d love to see the ability to refer to user\_fields by their name (seems much less brittle?) but this explanation and info you’ve provided me is enormously helpful. I appreciate it 🙂

---

<div class="post-metadata">

### Author: ![mattdm](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mattdm/32/216484_2.png) [@mattdm](https://meta.discourse.org/u/mattdm)
#### Post date: [December 2, 2021, 3:50am UTC](https://meta.discourse.org/t/how-to-change-user-fields-with-api/147999/5 "2021-12-02T03:50:22Z")

</div>

> [@blake](#):
>
> You can create a user with custom fields via the API by passing in `user_fields[1]` like this:

Do you use the same POST endpoint to _update_ a user? Are all fields required?

---

<div class="post-metadata">

### Author: ![micoHuang](https://avatars.discourse-cdn.com/v4/letter/m/7feea3/32.png) [@micoHuang](https://meta.discourse.org/u/micoHuang)
#### Post date: [March 16, 2023, 8:49am UTC](https://meta.discourse.org/t/how-to-change-user-fields-with-api/147999/6 "2023-03-16T08:49:37Z")

</div>

hello! I want to know how to get index of user\_fields? I should go to the web controller and get the index?Is there have api for getting the user\_fields? Then i could get the index. Thanks.

---

<div class="post-metadata">

### Author: ![blake](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/blake/32/157322_2.png) [@blake](https://meta.discourse.org/u/blake)
#### Post date: [March 16, 2023, 2:36pm UTC](https://meta.discourse.org/t/how-to-change-user-fields-with-api/147999/7 "2023-03-16T14:36:56Z")

</div>

> [@riking](#):
>
> `/admin/customize/user_fields` is a UI page where the custom user fields are configured.

> [@micoHuang](#):
>
> I want to know how to get index of user\_fields?

You can make a GET request to `/admin/customize/user_fields` and it will return a list of user fields:

```plaintext
{
  "user_fields": [
    {
      "id": 2,
      "name": "Favorite OS",
      "description": "What is your favorite Operating System?",
      "field_type": "text",
      "editable": true,
      "required": false,
      "show_on_profile": true,
      "show_on_user_card": true,
      "searchable": false,
      "position": 1
    }
  ]
}

```

---

<div class="post-metadata">

### Author: ![micoHuang](https://avatars.discourse-cdn.com/v4/letter/m/7feea3/32.png) [@micoHuang](https://meta.discourse.org/u/micoHuang)
#### Post date: [March 22, 2023, 3:07am UTC](https://meta.discourse.org/t/how-to-change-user-fields-with-api/147999/9 "2023-03-22T03:07:12Z")

</div>

Thanks. Your answer is very helpful to me!
