Jump to content

API creating polls in topics


NAWAC
Go to solution Solved by Stuart Silvester,

Recommended Posts

I am using the API to create topics successfully. However, I cannot seem to be able to add a poll to a topic via the API . Here is what I'm using as my post fields that is sent to the API via curl. Note, everything below the /* poll variables below */ comment is what I'm trying to post as the poll data to the topic. The topic still gets posted, but the poll does not get created in the topic.  What am I doing wrong?

               

$post_fields = array(
                    'key'             => urlencode($apiKey) // the topic id
                    ,'forum'         => urlencode(IPBFORUM_ID) // the forum id
                    ,'title'        => urlencode('This is the title') // the title
                    ,'post'         => urlencode($message)
                    ,'author'        => urlencode($user_id)
                    ,'author_name'    => urlencode($author_name) 
                    ,'hidden'         => urlencode('0')

		    /* poll variables below */
                    ,'poll_title'    => 'Cast your vote'
                    // poll_options: Array of objects with keys 'title' (string), 'answers' (array of objects with key 'value' set to the choice) and 'multichoice' (bool)
                    ,'poll_options' => array('title'        => urlencode('Make your choice, either Yes or No:')
                                            ,'answers'        => array('Yes','No')
                                            ,'multichoice'     => '0'
                                            )
                    ,'poll_public'    => '0' // bool     Make the poll public
                    ,'poll_only'    => '0' // bool     Make this a poll-only topic
                );

 

Edited by NAWAC
Link to comment
Share on other sites

  • Solution

You would need to send the options formatted for HTTP POST, you can't just pass an array through like that.

Something like this would work.

	/* poll variables below */
,'poll_title'    => 'Cast your vote'
	// poll_options: Array of objects with keys 'title' (string), 'answers' (array of objects with key 'value' set to the choice) and 'multichoice' (bool)
,'poll_options[1][title]' => urlencode('Make your choice, either Yes or No:')
	,'poll_options[1][answers][0][value]'        => 'Yes'
	,'poll_options[1][answers][1][value]'        => 'No'
	,'poll_options[1][multichoice]'     => '0'

,'poll_public'    => '0' // bool     Make the poll public
,'poll_only'    => '0' // bool     Make this a poll-only topic

 

You also don't need to urlencode everything like that, cURL sends data as application/x-www-form-urlencoded by default.

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...