# Posting new topic via the API not working

**URL:** <https://meta.discourse.org/t/posting-new-topic-via-the-api-not-working/70830>\
**Category:** Product Support\
**Created:** [26.Сентябрь.2017 20:14:13 UTC](https://meta.discourse.org/t/posting-new-topic-via-the-api-not-working/70830 "2017-09-26T20:14:13Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![lkramer](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lkramer/32/83897_2.png) [@lkramer](https://meta.discourse.org/u/lkramer)\
**Post date:** [27.Сентябрь.2017 14:12:09 UTC](https://meta.discourse.org/t/posting-new-topic-via-the-api-not-working/70830/3 "2017-09-27T14:12:09Z")

</div>

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';

```

---

_[View the full topic](https://meta.discourse.org/t/posting-new-topic-via-the-api-not-working/70830)._
