API endpoint for voting

AI 生成的摘要

In a discussion about API endpoints for voting in Discourse, drzraf notes that while voting functionality exists in the poll plugin (including Poll::vote and add_anonymous_votes), there’s no documented API endpoint or controller for it — and questions whether plugins can expose their own endpoints. Falco clarifies that voting is handled via the #plugin:voting plugin, not core Discourse, and provides example curl commands for voting/unvoting via voting/vote and voting/unvote endpoints. drzraf asks about anonymous voting and token requirements, and mentions docs.discourse.org doesn’t work in Firefox — a claim blake disputes. blake later confirms the controller and routes for voting are indeed inside plugin.rb, and explains that anonymous voting requires no token, but non-anonymous voting does. He also plans to expand API documentation to include plugin endpoints, suggesting tagging plugins in docs, and recommends using Chrome’s network inspector to explore endpoints in the meantime.

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

The API seems to lack a “votes” definition
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

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'

how, thanks! (I couldn’t find it inside 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?

Vote is a plugin, docs are only for core.

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.

I’m able to load 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?

The controller is inside of plugin.rb here:

And the routes for it are here:

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

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.

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.