# 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:** [September 26, 2017, 8:14pm UTC](https://meta.discourse.org/t/posting-new-topic-via-the-api-not-working/70830 "2017-09-26T20:14:13Z")\
**Posts on this page:** 5\
**Page:** 1

## AI-generated summary

In a [Support](/t/posting-new-topic-via-the-api-not-working/70830) thread titled "Posting new topic via the API not working," [lkramer](/t/posting-new-topic-via-the-api-not-working/70830/1) initially struggled to create a test topic via Discourse’s API, receiving a list of latest posts instead of a successful post. They shared their malformed GET request URL with unencoded spaces in title and raw fields, and incorrect HTTP method usage. [blake](/t/posting-new-topic-via-the-api-not-working/70830/2) advised checking the request method (should be POST), recommended tools like Postman, and flagged the space issue in parameters. Following this, [lkramer](/t/posting-new-topic-via-the-api-not-working/70830/3) resolved the issue by: 1) using `http_build_query()` to properly encode parameters, and 2) ensuring the title and message met Discourse’s minimum length requirements (e.g., "test" alone fails). They shared a working PHP cURL example that POSTs to `posts.json` with proper authentication, title, raw content, and category — intended to let WordPress users auto-post introductions or questions to their Discourse forum. The key takeaways are: always use POST, encode parameters, and meet Discourse’s content length rules.

<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:** [September 26, 2017, 8:14pm UTC](https://meta.discourse.org/t/posting-new-topic-via-the-api-not-working/70830/1 "2017-09-26T20:14:13Z")

</div>

Hello. I’ve read the documentation and searched for examples here but I can’t seem to get a simple test topic working. Here’s what I’m doing:

`https://my-forum-url/posts.json?title=this is a test topic via the api&category=5&raw=this is the test message part also via the api&api_key=my-forum-key&api_username=system`

Every time I execute it, it returns a list of the latest posts.

Any ideas? Thanks!

---

<div class="post-metadata">

**Author:** ![blake](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/blake/32/157322_2.png) [@blake](https://meta.discourse.org/u/blake)\
**Post date:** [September 26, 2017, 9:39pm UTC](https://meta.discourse.org/t/posting-new-topic-via-the-api-not-working/70830/2 "2017-09-26T21:39:08Z")

</div>

Could you give us a little bit more detail on how you are using the api? Are you trying this with curl? are you using postman (if not, I would highly recommend it)? Are you making a POST request?. Are you getting any errors back? My first thought is that you have spaces in your raw and title params and this probably won’t work if you are using curl.

---

<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:** [September 27, 2017, 2:12pm 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';

```

---

<div class="post-metadata">

**Author:** ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)\
**Post date:** [October 23, 2019, 4:06pm UTC](https://meta.discourse.org/t/posting-new-topic-via-the-api-not-working/70830/4 "2019-10-23T16:06:33Z")

</div>

Automatically bumped on October 23, 2019, 4:06pm UTC



---

<div class="post-metadata">

**Author:** ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)\
**Post date:** [October 23, 2019, 5:09pm UTC](https://meta.discourse.org/t/posting-new-topic-via-the-api-not-working/70830/5 "2019-10-23T17:09:09Z")

</div>

Closed on October 23, 2019, 5:09pm UTC


