# Are custom\_fields on posts/topics available via the API?

**URL:** https://meta.discourse.org/t/are-custom-fields-on-posts-topics-available-via-the-api/49455
**Category:** Development
**Created:** [8월 30, 2016, 7:51오후 UTC](https://meta.discourse.org/t/are-custom-fields-on-posts-topics-available-via-the-api/49455 "2016-08-30T19:51:06Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![cappslock](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cappslock/32/120789_2.png) [@cappslock](https://meta.discourse.org/u/cappslock)
#### Post date: [8월 30, 2016, 7:51오후 UTC](https://meta.discourse.org/t/are-custom-fields-on-posts-topics-available-via-the-api/49455/1 "2016-08-30T19:51:06Z")

</div>

I see from some digging that a `custom_fields` property exists on posts/topics and plugins make extensive use of it.

Is this field available through the API? Can it be set? Can it be queried against? Could a search be made for a topic with a certain value for a custom field?

---

<div class="post-metadata">

### Author: ![jgujgu](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jgujgu/32/64012_2.png) [@jgujgu](https://meta.discourse.org/u/jgujgu)
#### Post date: [11월 16, 2016, 3:31오후 UTC](https://meta.discourse.org/t/are-custom-fields-on-posts-topics-available-via-the-api/49455/2 "2016-11-16T15:31:01Z")

</div>

I have this exact same question. All the dialogue I see is about custom fields for users, not a general discussion 😕

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [11월 16, 2016, 5:57오후 UTC](https://meta.discourse.org/t/are-custom-fields-on-posts-topics-available-via-the-api/49455/3 "2016-11-16T17:57:00Z")

</div>

> [@jgujgu](#):
>
> I have this exact same question. All the dialogue I see is about custom fields for users, not a general discussion

Custom Fields are possible for topics, categories, users and posts.

Users are the common case, and can be created from the Admin UI and filled in user preferences.

All types can be handled in plugins, created, modified and read.

Using a custom field would be:

- Creating the field in the plugin.rb
- Adding it to some serializer so it’s avaliable for the front-end code
- Using it in a handlebars template

Many plugins use this fields like:

- [Poll](https://github.com/discourse/discourse/tree/master/plugins/poll) for Post Custom Fields
- [Signatures](https://github.com/xfalcox/discourse-signatures) for User Custom Fields
- [Solved](https://github.com/discourse/discourse-solved/blob/master/plugin.rb) Post and Topic Custom Fields

---

<div class="post-metadata">

### Author: ![jgujgu](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jgujgu/32/64012_2.png) [@jgujgu](https://meta.discourse.org/u/jgujgu)
#### Post date: [11월 17, 2016, 12:49오전 UTC](https://meta.discourse.org/t/are-custom-fields-on-posts-topics-available-via-the-api/49455/4 "2016-11-17T00:49:47Z")

</div>

@Falco thank you for the clarification. I will look to these plugins as examples.

I finally found what I was looking for… `register_custom_field_type()`. Prior to seeing this, I was rather confused on how the database handled the type information. Well, now I know 😃

---

<div class="post-metadata">

### Author: ![ebadgley](https://avatars.discourse-cdn.com/v4/letter/e/e19b73/32.png) [@ebadgley](https://meta.discourse.org/u/ebadgley)
#### Post date: [3월 7, 2017, 6:14오후 UTC](https://meta.discourse.org/t/are-custom-fields-on-posts-topics-available-via-the-api/49455/5 "2017-03-07T18:14:04Z")

</div>

@Falco a belated thanks for the link to the Signatures plugin. Not only do I wholeheartedly approve of old-style forum signatures, but it’s a great example of putting user custom fields to work for this new Discourse developer.

---

<div class="post-metadata">

### Author: ![bletch](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bletch/32/69088_2.png) [@bletch](https://meta.discourse.org/u/bletch)
#### Post date: [10월 24, 2018, 8:26오전 UTC](https://meta.discourse.org/t/are-custom-fields-on-posts-topics-available-via-the-api/49455/6 "2018-10-24T08:26:13Z")

</div>

Sorry for resurrecting an old thread, but I haven’t been able to answer this question by searching meta.

Are custom\_fields available on post/topics via the API?

In the answer [above](https://meta.discourse.org/t/are-custom-fields-on-posts-topics-available-via-the-api/49455/3), @Falco talks about how custom\_fields are available to the plugin developer, but I see no definitive answer to the question in the topic title. My own experience suggests that they are NOT available via the API.

I’m developing in Ruby with the Ruby API gem but can’t seem to pass a custom\_field value like others. My Ruby code is standalone so I can’t just use the Rails infrastructure to access custom\_fields.

From memory, when I developed my migration script from MVCF, the custom\_fields have to be added to an already existing parent. i.e. the parent is re-found, custom\_fields added and the parent re-saved. I can see why that might not be straightforward with the API.

I need to pass custom\_fields to categories and to topics (for the [Events plugin](https://meta.discourse.org/t/events-plugin-calendar/69776)) is it impossible or am I missing a trick?

Any help gratefully received.

---

<div class="post-metadata">

### Author: ![angus](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/angus/32/341715_2.png) [@angus](https://meta.discourse.org/u/angus)
#### Post date: [10월 24, 2018, 8:49오전 UTC](https://meta.discourse.org/t/are-custom-fields-on-posts-topics-available-via-the-api/49455/7 "2018-10-24T08:49:24Z")

</div>

You can post events plugin events via the API. There’s an example here:

> [@Events Plugin calendar](https://meta.discourse.org/t/events-plugin-calendar/69776/28):
>
> It is now slight_smile[https://github.com/angusmcleod/discourse-events/commit/33ba86f66e22afaab30dd64eb0e51e45f17860c9](https://github.com/angusmcleod/discourse-events/commit/33ba86f66e22afaab30dd64eb0e51e45f17860c9) To add a date and time when creating a topic, pass a JSON event string with start and end set as datetimes in ISO 8601 format. Example request: curl -X POST \ https://your\_site/posts \ -H 'cache-control: no-cache' \ -H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' \ -F api\_key=your\_key \ -F api\_username=your\_username \ -F …

---

<div class="post-metadata">

### Author: ![bletch](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bletch/32/69088_2.png) [@bletch](https://meta.discourse.org/u/bletch)
#### Post date: [10월 24, 2018, 9:09오전 UTC](https://meta.discourse.org/t/are-custom-fields-on-posts-topics-available-via-the-api/49455/8 "2018-10-24T09:09:51Z")

</div>

You, sir, are a gent of the highest order!

It’s working now.

For fellow travellers, it seems that you can’t use the Ruby API gem’s `create_topic` method…

```ruby
client.create_topic(...)

```

…as it _looks like_ the API only passes known fields through.

Instead, I had to use the raw client’s post method, like so:

```ruby
args = {
  title: title,
  raw: content,
  category: child_category["id"],
  event: {
    "start" => event_start.to_s,
    "end" => event_end.to_s
  }
}
new_topic = client.post("/posts", args.to_h)

```

EDIT: I can live with not being able to set the settings for the event plugin at the category level as that is pretty much a one-time thing.

PS, @angus, why did it take you 24 minutes to respond - I expect better service that than! **\***

**\*** for the avoidance of doubt, this is dripping with British sarcasm and irony.

🙂
