# API endpoint for voting

**URL:** https://meta.discourse.org/t/api-endpoint-for-voting/64754
**Category:** Development
**Tags:** polls, rest-api
**Created:** [19 Giugno 2017, 3:03pm UTC](https://meta.discourse.org/t/api-endpoint-for-voting/64754 "2017-06-19T15:03:28Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![drzraf](https://avatars.discourse-cdn.com/v4/letter/d/50afbb/32.png) [@drzraf](https://meta.discourse.org/u/drzraf)
#### Post date: [19 Giugno 2017, 3:03pm UTC](https://meta.discourse.org/t/api-endpoint-for-voting/64754/1 "2017-06-19T15:03:28Z")

</div>

That would open the vote feature to mobile user, external app’, …

[The API seems to lack a “votes” definition](https://github.com/discourse/discourse_api_docs/tree/master/definitions)  
[The Poll::vote](https://github.com/discourse/discourse/blob/master/plugins/poll/plugin.rb#L35) and [add\_anonymous\_votes function](https://github.com/discourse/discourse/blob/master/plugins/poll/spec/helpers.rb) is already there, but lack a [controller](https://github.com/discourse/discourse/tree/master/app/controllers) but since votes are a plugin, the issue may have to be that [plugins get the ability open API endpoints](https://github.com/angusmcleod/discourse-ratings/issues/9)

---

<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: [19 Giugno 2017, 3:09pm UTC](https://meta.discourse.org/t/api-endpoint-for-voting/64754/2 "2017-06-19T15:09:07Z")

</div>

Everything in Discourse has API support:

Vote:

```
curl 'https://meta.discourse.org/voting/vote' -X POST --data 'topic_id=51247'

```

Unvote:

```
curl 'https://meta.discourse.org/voting/unvote' -X POST --data 'topic_id=51247'

```

---

<div class="post-metadata">

### Author: ![drzraf](https://avatars.discourse-cdn.com/v4/letter/d/50afbb/32.png) [@drzraf](https://meta.discourse.org/u/drzraf)
#### Post date: [19 Giugno 2017, 3:23pm UTC](https://meta.discourse.org/t/api-endpoint-for-voting/64754/3 "2017-06-19T15:23:25Z")

</div>

how, thanks! (I couldn’t find it inside [http://docs.discourse.org/](http://docs.discourse.org/) [which does not work with FF btw])  
How does is apply/not apply to anonymous users?  
Will that call require user’s token if anonymous voting is not allowed?

---

<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: [19 Giugno 2017, 3:26pm UTC](https://meta.discourse.org/t/api-endpoint-for-voting/64754/4 "2017-06-19T15:26:17Z")

</div>

> [@drzraf](#):
>
> I couldn’t find it inside [http://docs.discourse.org/](http://docs.discourse.org/)

Vote is a plugin, docs are only for core.

> [@drzraf](#):
>
> The Poll::vote and add\_anonymous\_votes function is already there, but lack a controller but since votes are a plugin, the issue may have to be that plugins get the ability open API endpoints

OMG, just saw this now. You created a post on the #plugin:voting category and are asking questions linking the poll plugin code. My last reply was about the #plugin:voting plugin, please elucidate me.

---

<div class="post-metadata">

### Author: ![blake](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/blake/32/157322_2.png) [@blake](https://meta.discourse.org/u/blake)
#### Post date: [19 Giugno 2017, 4:00pm UTC](https://meta.discourse.org/t/api-endpoint-for-voting/64754/5 "2017-06-19T16:00:48Z")

</div>

> [@drzraf](#):
>
> which does not work with FF btw

I’m able to load [http://docs.discourse.org](http://docs.discourse.org) in firefox 54.0 on Windows just fine and I know it worked on earlier versions too. Is it really not working for you in firefox?

---

<div class="post-metadata">

### Author: ![blake](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/blake/32/157322_2.png) [@blake](https://meta.discourse.org/u/blake)
#### Post date: [19 Giugno 2017, 4:21pm UTC](https://meta.discourse.org/t/api-endpoint-for-voting/64754/6 "2017-06-19T16:21:30Z")

</div>

> [@drzraf](#):
>
> but lack a controller

The controller is inside of plugin.rb here:

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

And the routes for it are here:

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

> [@drzraf](#):
>
> Will that call require user’s token if anonymous voting is not allowed?

If anonymous voting is not allowed it should require a users token.

> [@Falco](#):
>
> Vote is a plugin, docs are only for core.

I’m thinking about adding the api endpoints for plugins as well to the api docs. I can just create a tag in the docs for each plugin that is added.

> [@drzraf](#):
>
> I couldn’t find it inside [http://docs.discourse.org/](http://docs.discourse.org/)

I’ll work on adding the poll endpoints to the docs. In the meantime though you can just open up the chrome inspector and go the networks xhr tab and view the requests as you make them.
