# Custom user fields not available in api

**URL:** https://meta.discourse.org/t/custom-user-fields-not-available-in-api/346745
**Category:** Development
**Tags:** rest-api, user-custom-fields
**Created:** [January 12, 2025, 2:44pm UTC](https://meta.discourse.org/t/custom-user-fields-not-available-in-api/346745 "2025-01-12T14:44:43Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![markschmucker](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/markschmucker/32/141599_2.png) [@markschmucker](https://meta.discourse.org/u/markschmucker)
#### Post date: [January 12, 2025, 2:44pm UTC](https://meta.discourse.org/t/custom-user-fields-not-available-in-api/346745/1 "2025-01-12T14:44:43Z")

</div>

I define a new user custom field:

```plaintext
User.find_each do |user|
  user.custom_fields['foo'] = 0
  user.save_custom_fields
end

```

That works- now each user has 8 custom fields:

```plaintext
[18] pry(main)> User.find(1).custom_fields
=> {
 "patreon_id"=>"83297319",
 "last_chat_channel_id"=>32,
 "last_digest_special_post"=>"275200",
 "last_digest_favorite_post"=>"279347",
 "example_field"=>"new value",
 "ai_bot_query_count"=>"0",
 "ai_bot_query_date"=>"2025-01-12",
 "foo"=>"0"}

```

[Data Explorer](https://meta.discourse.org/t/32566?silent=true) sees the new field:

```plaintext
SELECT * from user_custom_fields
WHERE name LIKE '%foo%'
LIMIT 10

```

Now I want to use the foo field in javascript. I add some code at `/admin/customize/themes/3/common/head_tag/edit`. But only 2 of the 8 show up:

```plaintext
api.getCurrentUser().custom_fields

{
  last_chat_channel_id: 32,
  ai_bot_query_count: '0'
}

```

What am I missing?

---

<div class="post-metadata">

### Author: ![Moin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/moin/32/554653_2.png) [@Moin](https://meta.discourse.org/u/Moin)
#### Post date: [January 12, 2025, 2:51pm UTC](https://meta.discourse.org/t/custom-user-fields-not-available-in-api/346745/2 "2025-01-12T14:51:26Z")

</div>

Did you add your user fields to the `public user custom fields` site setting?

 ![Screenshot_20250112_155100_Firefox](https://global.discourse-cdn.com/meta/original/4X/8/6/0/86024d3a6b112a03e4636d11353122329dcfd741.jpeg)

> [@Adding non-visible user custom fields to the API](https://meta.discourse.org/t/adding-non-visible-user-custom-fields-to-the-api/276618/1):
>
> bookmark This guide explains how to expose user custom field data through the API without displaying it on a user card. person_raising_hand Required user level: Administrator This guide will walk you through the process of making User Custom Field data accessible via the API without displaying it on a user card. This can be useful when you need to programmatically access custom user data while keeping it hidden from general view. Creating a User Custom Field First, create your User Cu…

---

<div class="post-metadata">

### Author: ![markschmucker](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/markschmucker/32/141599_2.png) [@markschmucker](https://meta.discourse.org/u/markschmucker)
#### Post date: [January 12, 2025, 3:05pm UTC](https://meta.discourse.org/t/custom-user-fields-not-available-in-api/346745/3 "2025-01-12T15:05:27Z")

</div>

Thanks, that did the trick.

One more question- are these custom user fields a different thing?:

> [@Creating and configuring custom user fields](https://meta.discourse.org/t/creating-and-configuring-custom-user-fields/113192):
>
> bookmark This guide explains how to create and configure custom user fields in Discourse, including how to add them to the signup form, user profiles, and user directory. person_raising_hand Required user level: Administrator Custom user fields allow you to collect additional information from your users beyond the standard profile fields. These fields can be displayed on user cards, user summary pages, and even retrieved using the [Data Explorer](https://meta.discourse.org/t/32566?silent=true) plugin. This guide will walk you through th…

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [February 11, 2025, 3:05pm UTC](https://meta.discourse.org/t/custom-user-fields-not-available-in-api/346745/4 "2025-02-11T15:05:58Z")

</div>

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