Invision Community 4: SEO, prepare for v5 and dormant account notifications By Matt Monday at 02:04 PM
NAWAC Posted November 22, 2021 Posted November 22, 2021 (edited) 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 November 22, 2021 by NAWAC
Solution Stuart Silvester Posted November 23, 2021 Solution Posted November 23, 2021 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. NAWAC 1
Recommended Posts