Adding a b1 API endpoint for getting Poll by key
Hello, I have been using the new "b1" endpoints that @Rob Guthrie added recently for a Loomio integration I'm working on. I'd like to add a way to get a Poll's data (specifically stance_data
is what I care about). I am starting a Poll using the POST b1/polls
endpoint, and then waiting for a webhook event to notify me that the poll is closed. At that point I would like to know the stance data of the poll (it is not contained in the webhook event body).
My suggestion is adding index
to existing API::B1::PollsController
which returns a collection:
GET http://localhost:3000/api/b1/polls?poll_key=[key]&api_key=[key]
returns: Poll.where(key: params[:poll_key])
I already added it locally, so I can open a PR if the general idea sounds OK. Another approach could be to add an endpoint for stances
, or to include stance data in the webhook event body.
Thanks!
miriam Wed 10 Feb 2021 5:03PM
Perfect, thanks @Rob Guthrie!
miriam Thu 14 Oct 2021 5:54PM
Hey @Rob Guthrie! I have a bug report on a b1 endpoint, where's the best place to report that?
When using the b1/polls endpoint to create a poll, passing any of the following params cause a 500 response: recipient_audience
, recipient_user_ids
, recipient_emails
, and recipient_message
. I think it's because they are not attributes on Poll.
Here's a branch with failing tests, as an example https://github.com/loomio/loomio/compare/master...mashton:bugreport_b1_unknown_attribtues
Robert Guthrie Thu 14 Oct 2021 10:26PM
Hi @miriam, here's good. I'll fix this today. I saw the error come though sentry and wondered if that was you. Thanks for the extra reminder - I'm surprised I've not got a test for this. Will report back shortly.
Robert Guthrie Fri 15 Oct 2021 1:37AM
ok, @miriam, I've just deployed a fix for this, and written some tests, so I'm fairly confident you can now create a poll and invite people to it with a single API call, as you were intending.
miriam Fri 15 Oct 2021 1:48PM
Awesome it's working now, thanks for the quick fix @Rob Guthrie
Robert Guthrie · Tue 9 Feb 2021 11:12PM
Hi @miriam I've added new endpoints for show poll and show discussion.
For poll, It's a little different to how you have implemented it, but does the same thing.
You'll need to edit your API endpoint and add support for show_poll, and check out the updated API documentation.
It should include stance data too.