# Niet-zichtbare aangepaste gebruikersvelden toevoegen aan de API

**URL:** https://meta.discourse.org/t/adding-non-visible-user-custom-fields-to-the-api/276618
**Category:** Site Management
**Tags:** rest-api, how-to, user-custom-fields, users
**Created:** [25 augustus 2023 om 14:46 UTC](https://meta.discourse.org/t/adding-non-visible-user-custom-fields-to-the-api/276618 "2023-08-25T14:46:39Z")
**Posts on this page:** 1
**Showing post:** 1

<div class="post-metadata">

### Author: ![Discourse](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/discourse/32/148734_2.png) [@Discourse](https://meta.discourse.org/u/Discourse)
#### Post date: [25 augustus 2023 om 14:46 UTC](https://meta.discourse.org/t/adding-non-visible-user-custom-fields-to-the-api/276618/1 "2023-08-25T14:46:40Z")

</div>

> 🔖 This guide explains how to expose user custom field data through the API without displaying it on a user card.
> 
> 🙋 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

1. First, create your User Custom Field. For detailed instructions, refer to [the guide for creating and configuring custom user fields](https://meta.discourse.org/t/create-and-configure-custom-user-fields/113192) guide.
2. Once you’ve set up your custom field, save it.  
 ![test user custom field](https://global.discourse-cdn.com/meta/original/4X/3/1/6/31623658e1ecda7bf96645d26282151e6027749f.png)

## Finding the User Custom Field ID

1. Navigate to `/admin/config/user-fields.json` in your browser.
2. Locate your newly created custom field and note its ID number.  
 ![user_fields json](https://global.discourse-cdn.com/meta/original/4X/5/6/0/56077a67b3ca13aa4c29647467d3ecd8c39afcaa.png)

## Configuring API Access

1. Go to your site’s admin settings.
2. Find either the `public user custom fields` or `staff user custom fields` setting:
  - Use `public user custom fields` if you want the data to be accessible to all API users.
  - Use `staff user custom fields` if you want to restrict access to staff API keys only.

3. Enter the custom field in the format `user_field_X`, where X is the ID number you noted earlier.  
For example, if your custom field ID is 7, you would enter `user_field_7`.  
 ![user_field_X](https://global.discourse-cdn.com/meta/original/4X/3/a/4/3a48731bbf8a5ee63447a4c754361341d7426e58.png)

## Accessing the Custom Field Data

Once configured, the custom field data will be included in the `/u/[USERNAME].json` endpoint under the “User Fields” section.

 ![user fields - user json](https://global.discourse-cdn.com/meta/original/4X/6/4/3/64370e228d2492d193271fd04906423bcf49fba4.png)

## Searching Users by Custom Field Values

You can search for users based on their custom field values using the API:

1. Ensure the custom field has the “searchable” option checked in its settings.  
 ![image](https://global.discourse-cdn.com/meta/original/4X/0/f/a/0fae82138df105e865c2ce611dd93b8f87f639c9.png)
2. Use the `/directory_items.json` endpoint with your query parameters.

Here’s an example API call:

```plaintext
https://yourdomain.com/directory_items.json?period=weekly&order=likes_received&name=SearchTerm&user_field_ids=1|2

```

- `user_field_ids`: Specify which custom fields to search (e.g., `user_field_ids=5` to search only in custom field ID 5).
- `name`: The search term to look for in custom fields, usernames, and possibly full names.

_Note: This search is not exclusive to custom fields and may return results based on username or full name matches as well._

For more details on available parameters, consult the [API documentation](https://docs.discourse.org/#tag/Users/operation/listUsersPublic).

## Additional Resources

- [Creating and configuring custom user fields](https://meta.discourse.org/t/create-and-configure-custom-user-fields/113192)
- [Discourse API Docs](https://docs.discourse.org/#tag/Users/operation/listUsersPublic)
- [Reverse engineer the Discourse API](https://meta.discourse.org/t/reverse-engineer-the-discourse-api/20576)

> Last edited by @MarkDoerr 2025-03-28T01:41:22Z
> 
> Last checked by @hugh 2024-07-09T11:12:48Z
> 
> > **Check document**
> >
> > Perform check on document:

---

_[View the full topic](https://meta.discourse.org/t/adding-non-visible-user-custom-fields-to-the-api/276618)._
