Posting new topic via the API not working

Thanks for the reply! I ended up scrutinizing my php code a bit more and got it working! First mistake was not wrapping the query args in http_build_query (thanks to your clue about spaces). Second mistake was that you have to adhere to Discourse’s rules about the title and message not being too brief (e.g, “test” / “test” doesn’t post).

Here’s the basic working proof of concept code in case anyone finds it useful. We’re planning to use it to allow people to introduce themselves or ask a question via our main site (wordpress-powered).

// change this to your forum's info
$api_key="real-api-key-here";
$api_user="system";
$url_base="https://real-forum-url-here/";
$api_auth="api_key=" . $api_key . "&api_username=" . $api_user;

// title and message
$title = $_GET['dt'];
$message = $_GET['dm'];

$ch = curl_init();	

$query_args = array(
'title' => $title,
'raw' => $message,
'category' => 7,
);

$url=$url_base . "posts.json?" . $api_auth;

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($query_args) );
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);

$response = curl_exec($ch);

echo '<br>response-start:';
print_r($response);
echo ':response-end';