Posting a poll via the API is not working

(Erik Chan) #1

@cpradio Weirdly, posting a poll as raw seemed to have broke recently (or maybe it was never working perfectly).

I can now see a poll rendered in my forum, but none of the buttons to vote work. It seems like no post request is fired off when click on vote buttons. No javascript errors in browser console either.

Here is a link:

If I edit the post and save it, the voting buttons will start working. But not otherwise via direct API forum post. Any thoughts?

(Erik Chan) #2

Randomly found this thread. But I am not using the checklist plugin.

The only plugins I have installed are:

(cpradio) #3

What version of Discourse are you running?

I only ask, because we’re still on beta6 and it works on that version. This may have regressed, but I don’t have a quick way to test that yet.
Discourse 1.5.0.beta6 - GitHub - discourse/discourse: A platform for community discussion. Free, open, simple. version 95fe29392f36076f38326a65766f4ef9cf93e0bc

(Erik Chan) #4

I’m on Discourse version: v1.5.0.beta6

(Erik Chan) #5

Did some extra tests to make sure its not something silly on my side. I ran the excerpt below on rails console, and the resulting forum post also displayed a poll that couldn’t be voted on.

@poll = "[poll name=test]\n- Green\n- Blue\n[/poll]"
client.create_topic(category: "staff", skip_validations: true, auto_track: true, title: "test", raw: @poll)

(Sam Saffron) #6

Can you try running against latest?

(Erik Chan) #7

Just upgraded to latest, reposted to the forum, and still no luck

(Erik Chan) #8

Looks like upgrading to latest broke my site now :cold_sweat:

My site depends on the counts from the activity page sigh

(Erik Chan) #9

Anything I should look at or try about this?

(Sam Saffron) #10

there is no magic about posting polls, are you using the Discourse api gem? @techAPJ can you confirm the sample there works?

(Erik Chan) #11

Yes, using the discourse api gem

(Erik Chan) #12

Checking in to see where this is at. Any luck @techAPJ?

(Arpit Jalan) #13

Yes, I am able to repro this when creating poll topic via API. Looking more into it.

(Arpit Jalan) #14

I spent considerable time on this issue today … to find out that this is not even an issue… :neutral_face:

To create polls via API the option skip_validations must be false, because the polls custom field is being prepared in polls validation code.

So the API code for creating poll topic will be:

  category: "general",
  skip_validations: false,
  auto_track: false,
  title: "Your Favorite Color?",
  raw: "[poll name=color]\n- Green\n- Blue\n- Red\n[/poll]"

Added an example for same in discourse_api gem:

Creating poll via API raw parameter markdown
(Erik Chan) #15

You are awesome! How can I buy you a coffee/beer :grinning:

(Arpit Jalan) #16

Thank You!

Spread the word about Discourse! :slightly_smiling: