Loomio

API Issues

Robert Guthrie PublicSeen by 97

Hi Shauna, I thought I'd start the thread to ask what issues you're experiencing with the API. Thanks for giving it a go. I'm keen to improve it based on feedback, and I love the metagov project.

Shauna Gordon-McKeon

Hi Rob, thanks for the quick response! I'm trying to start a new vote on an existing thread in a subgroup, using the recipient_user_ids parameter listed here https://www.loomio.org/help/api?api_key=xThe to notify/invite everyone in the subgroup that the thread is in. But I'm the only one getting an email invite or showing up as invited in the vote. (The account doing the invite is a separate bot account, so as far as I can tell there's no reason for me to be special and get the invite, except that I'm an admin.)

Shauna Gordon-McKeon

Hi @Rob Guthrie, any thoughts on what could be going wrong here?

Robert Guthrie

Hi @Shauna Gordon-McKeon, so sorry I did not see your first reply.

I've updated the API documentation, so the examples all work when you paste them into your terminal. I've tested the updated create poll example and it does send email notifications out. Please give it a go and let me know how you get on.

Good luck, and thank you!

Robert Guthrie

Damn, I'm so sorry, @Shauna Gordon-McKeon

I was sure that was working, wow, how strange. I've had a look and confirmed it does send notifications. I'll try to fix this tomorrow.

Shauna Gordon-McKeon

Were you able to figure out what's going on? If not, maybe we could do a videocall and try to work this out synchronously?

Robert Guthrie

Hi Shauna, I've fixed this issue just now. It's taken a long time just because I had to a large branch to finish first - I'm sorry to leave you hanging!

Both discussion and poll examples in the documentation page work correctly for me now. I hope this works for you and is still relevant :)

Robert Guthrie

Oh, I should mention: I've updated the poll results format.

There is now a poll.results array, with all the results neatly calculated. I'd be happy to have a call if you want to discuss how you're using the API, or have any other questions.

Shauna Gordon-McKeon

We did some debugging of our own last week and finally discovered that adding a [] to recipient_emails and recipient_user_ids (ie "recipient_emails[]": [x,y,z]) fixed the issue.

It was a pain to figure out for two reasons:

1) the notifications weren't never working - they did send to the last person in the list. until we figured that out, the pattern of "this works! no wait it doesn't!" was very confusing.

2) the issue only arises when we send the call from our code, not when we use CURL

We were surprised to discover that adding [] fixed the issue, since we thought that was deprecated syntax and is no longer in your docs. Our code was calling requests.post(url, data), without specifying that the data ought to be json, so we suspect that we were sending it as form data. And that your API is for some reason handling form data differently than json data.

Anyway, we're more or less okay on our end. Just wanted to pass that info along so you can clarify the json/form data distinction (if possible).

Robert Guthrie

Nice work. I changed the documentation examples to use json rather than form data last time I did a big update. It just looks so much simpler to me.

It's rails code, not Loomio code, that parses the json or form data and presents me with just a "params" object. So this aspect of parsing the incoming data has likely not changed recently.

The array[] thing is something php introduced, I think. You're supposed to use it like array[]=1&array[]=2&array[]=3 to send array=[1,2,3].

Anyway, I'm so sorry you had issues and I took a long time to respond. I am committed to improving the API with the feedback I get. So please let me know if there is something I can do. With a little time, I'm sure I can help.

Robert Guthrie

Have you seen the new poll.results data format? Is that useful for you?

Robert Guthrie

Could you send me a video of this? I've just tested it and it seems to work properly. We did have this bug reported 2 weeks ago, but I've since fixed it (or so I thought).

Shauna Gordon-McKeon

Ack, sorry - pretty sure it was an issue on our end. I meant to update this thread but forgot. I'll let you know if the fix I found for it stops working!