Add new API endpoints

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!

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

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.

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)

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 ?

Read the poll plugin code:

It has a controller and a route.

4 Likes

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

3 Likes