The discussion revolves around issues with posting new topics via the Discourse API. Users report receiving a 404 error when attempting to create posts, despite using valid credentials. vavalomi notes the request works under an admin user but fails with a regular user, even with a master API key. riking clarifies that standard form encoding is required and suggests using either (api_username, api_key) or (Cookie, X-CSRF-Token). iajrz observes that posts succeed for staff users but fail for others, suspecting a bug, and finds a workaround by creating posts under one user and transferring ownership. Tarun_Sharma asks about uploading images, and Canapin explains that images must be uploaded via the uploads endpoint first, then referenced in the post using the returned short_url.
I cannot seem to make posting work and unfortunately couldn’t find much neither in api docs, nor on the forum -
What type of encoding/cleaning (if any) do I have to do for the title and raw post body strings? I’m strangely getting 404 when posting on /posts.json with {api_username, api_key, title, raw, created_at, achetype, skip_validations} fields with form-data header (trying with python but postman gives the same). Any pointers to what am I doing wrong?
But am I supposed to receive 404 in any case? I do include api_username and api _key in the form…
Update: if I send the same request under admin user / master api_key it goes through, but I get 404 if I submit under another user but still with master api_key, bug or my mistake?
Hello - I don’t want to create a new topic because I seem to be having the exact same issue; I’m using the latest discourse_api gem, and I have generated a master API key; I’m creating posts on behalf of existing users (fetching content they put elsewhere).
Works on some users, and not on others; I get a {"status"=>404, "error"=>"Not Found"} response.
Only differences I can tell are:
The user for whom I can create is in staff (others aren’t)
The user for whom I can create has a user name identical to the name, and is lowercase (others don’t and aren’t)
Furthermore, if I go to the web interface, create the post, and transfer ownership, it works. So far I’m letting the automaton do its job with the ones that can be created, and give me the text to manually create the ones that can’t. But at over 1000 posts that won’t be created automatically, I despair a little
EDIT: verified name situation is not the issue… It may be related to the staff thing.
EDITEDIT: I worked around this by creating in a user’s name, then changing ownership to another user. The mere fact that this is possible on the same API key makes me lean towards the 404 behavior being a bug.