# Add new API endpoints

**URL:** https://meta.discourse.org/t/add-new-api-endpoints/109898
**Category:** Support
**Created:** [February 23, 2019, 12:11pm UTC](https://meta.discourse.org/t/add-new-api-endpoints/109898 "2019-02-23T12:11:42Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![Alfarhan\_Zahedi](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/alfarhan_zahedi/32/141591_2.png) [@Alfarhan\_Zahedi](https://meta.discourse.org/u/Alfarhan_Zahedi)
#### Post date: [February 23, 2019, 12:11pm UTC](https://meta.discourse.org/t/add-new-api-endpoints/109898/1 "2019-02-23T12:11:42Z")

</div>

Hi.  
I need a API endpoint which is currently not present in the AOI provided by Discourse. How do I go about writing a plugin to extend the current API ?

Thank you!

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [February 23, 2019, 12:24pm UTC](https://meta.discourse.org/t/add-new-api-endpoints/109898/2 "2019-02-23T12:24:07Z")

</div>

First, back up and say what problem you are trying to solve. It may be that you don’t need a new endpoint. Have you looked at the 'reverse engineering" topic?

Next search for “plugin #howto”

---

<div class="post-metadata">

### Author: ![Alfarhan\_Zahedi](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/alfarhan_zahedi/32/141591_2.png) [@Alfarhan\_Zahedi](https://meta.discourse.org/u/Alfarhan_Zahedi)
#### Post date: [February 23, 2019, 12:30pm UTC](https://meta.discourse.org/t/add-new-api-endpoints/109898/3 "2019-02-23T12:30:44Z")

</div>

As per my need, I modified the users table to add a custom attribute (Discourse custom fields was not what suited my needs). Now, I need to be able to modify that particular attribute.

I need a new endpoint (just like the ‘update email’ endpoint) to modify this particular attribute from a external site.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [February 23, 2019, 12:34pm UTC](https://meta.discourse.org/t/add-new-api-endpoints/109898/4 "2019-02-23T12:34:04Z")

</div>

Are you saying that you forked discourse or that you did this in a plugin?

Assuming that it’s the latter, I would look for another plugin that adds an endpoint. (and hope that someone with better rails chops than I takes notice of this topic)

---

<div class="post-metadata">

### Author: ![Alfarhan\_Zahedi](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/alfarhan_zahedi/32/141591_2.png) [@Alfarhan\_Zahedi](https://meta.discourse.org/u/Alfarhan_Zahedi)
#### Post date: [February 23, 2019, 12:39pm UTC](https://meta.discourse.org/t/add-new-api-endpoints/109898/5 "2019-02-23T12:39:18Z")

</div>

Yes. I did that via a plugin that I wrote. All is working fine and I am able to access the attribute via the /users/{username}.json endpoint.

I do not know on how to begin writing the endpoint to modify that attribute.  
Do I need to add a new route and a controller for that route ?

Will this do it ?

Or is there something that I am missing ?

---

<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: [February 23, 2019, 2:57pm UTC](https://meta.discourse.org/t/add-new-api-endpoints/109898/6 "2019-02-23T14:57:43Z")

</div>

Read the poll plugin code:

> <https://github.com/discourse/discourse/blob/main/plugins/poll/plugin.rb#L300>

It has a controller and a route.

---

<div class="post-metadata">

### Author: ![Alfarhan\_Zahedi](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/alfarhan_zahedi/32/141591_2.png) [@Alfarhan\_Zahedi](https://meta.discourse.org/u/Alfarhan_Zahedi)
#### Post date: [February 23, 2019, 10:11pm UTC](https://meta.discourse.org/t/add-new-api-endpoints/109898/7 "2019-02-23T22:11:32Z")

</div>

Thanks. It helped.

Just in case someone else needs help in this particular topic, give this article a read - [How to create a Discourse plugin – kleinfreund.de](https://kleinfreund.de/how-to-create-a-discourse-plugin/)

---

<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: [March 23, 2022, 2:43pm UTC](https://meta.discourse.org/t/add-new-api-endpoints/109898/8 "2022-03-23T14:43:53Z")

</div>



---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [March 23, 2022, 8:55pm UTC](https://meta.discourse.org/t/add-new-api-endpoints/109898/9 "2022-03-23T20:55:01Z")

</div>


