The discussion revolves around updating a post using the Discourse API PUT request. alank initially asked about the correct structure for the JSON payload, specifically regarding the use of raw and raw_old. blake suggested using the raw field to replace the entire post and provided resources on how to reverse-engineer the Discourse API.
alank further clarified their goal of adding a comment and link below the category name, which is taken from the first post of the “About” topic. alank discovered that updating a post using “cooked” resulted in an error, but using “raw” was possible.
md-misko pointed out a discrepancy in the API documentation, which was later corrected by simon. The correct payload for PUT /posts/{id}.json should be a JSON object with the raw parameter, which is sufficient for replacing the entire post.
The purpose of raw_old remains unclear, and its use is not necessary for updating a post.
Before I attempt this, does this mean, or well.. what does this mean?
does this mean: {post: {raw: ..., raw_old: ... }}
Or simply {raw: "", raw_old: ""...}
And also what is raw_old? Only says that each element is a “string” of what I must PUT: in the JSON body.
I’m simply attempting to add a line at the top of the post (which was initially created by a Bot) where we need to add a link to another site - note also that towards the goal of having that first paragraph displayed under the Category title, or in the cooked
element to be shown (Defined just under the category title).
I’m not actually sure what raw_old is for at the moment, but you just need to use the raw field and it will replace the entire post. So, in your code you would fetch the post you want to edit, add your line to the top, then update the post using the raw field.
It might be helpful to see how Discourse does it by editing a post live on your site and inspecting the browser calls:
Just a question on this, are you referring to different documentation then what is defined at Discourse API Docs ? That would be interesting… however I am only going by the API docs.
My simple goal is to simply add a comment + link below the category name, which I think Discourse takes from the first Post of the "About … " topic? Like I’m just looking for what it will insert into the
… element or what I need to do to make my post appear there. Does my explanation make sense?
From the above, and from attempting, you can not update a post using “cooked” as the API documentation states, it is however possible with “raw”, all attempts I made using “cooked” kept giving me back an error that my post was invalid as it was under 20 characters, or not a clear sentence …
However there are additional issues with “raw” that I will make into another post as this isn’t directly related.
Yes, thanks, I realized this after attempting a few Postman requests and playing around with it… also in my attempts, the “cooked” seemed to do nothing… and I’m still not sure what “raw_old” is.