gchiu sought clarification on performing an HTTP POST to create a reply in Discourse, noting confusion in the API docs between form-data and JSON formats, and uncertainty over endpoint paths like /posts vs /posts.json. After initial failures—including a misleading “Body too short” error gchiu and a CSRF token issue gchiu—they resolved it by including api_key and api_username in the URL query string (e.g., /posts.json?api_key=...&api_username=...), which worked despite documentation suggesting they belong in the POST body. blake clarified that both /posts and /posts.json are equivalent, and that api_key/api_username can be sent as POST parameters (not headers), providing a working curl example using multipart/form-data. gchiu confirmed their solution worked but noted they’d misread a prior post; they plan to switch to HTTPS. Finally, gchiu shared their use case: auto-posting GitHub commit logs and Travis-CI build links to a single topic for tracking, as seen at rebolchat.me/t/rebol3-ren-c-branch-change-logs/54.
but that post told me that I also need to include the api_key and api_name in the URL!
POST /posts.json?api_key=..very.long.api.key&api_username=thatsme HTTP/1.0
Accept: */*
Accept-Charset: utf-8
Host: www.rebolchat.me
User-Agent: REBOL
Content-Type: application/json
Content-Length: 234
{"title":"Bot Test","topic_id":36,"raw":"this is an api test that I am trying to see if I can make a post and it needs to be 20 characters","category":8,"name":"Graham","color":"49d9e9","text_color":"f0fcfd","created_at":"2017-05-19"}
Sorry for any confusion in the docs. Yes it is showing the example body as JSON mostly just for readability but yes you can create the request as form-data
They are ambiguous, are the same endpoint and will accept the exact same POST body. If the default happens to return JSON then I usually just leave off the .json. Some endpoints that don’t have the extension will return html instead.
That would work, but it actually said:
so you can put the api_key and api_username in the POST body not in the header.
Here is an example curl command for creating a post on a topic:
Bad csrf token when making api request
api_key and api_username are POST parameters, not headers.
so you can put the api_key and api_username in the POST body not in the header.
I must have linked to the wrong post. The one I read said that credentials could not be gleaned from the JSON payload, and you had to also include the api_key and api_username in the query string when using the .json endpoint. And it was only then that I managed to get a HTTP POST working for my bot.
Since it’s working that way I’m going to leave it like that for the moment though I should probably switch to using HTTPS.
I dunno if anyone else is interested but I was posting all of the commit logs of our builds from github, and then linking to the deployed binaries on S3 from travis-ci to a single topic so that we can easily track them together.