API PUT リクエストによる投稿の更新

API の Discourse ドキュメントにこのような構造が記載されているのですが、その意味がわかりません。

{
"post[raw]": "string",
"post[raw_old]": "string",
"post[edit_reason]": "string",
"post[cooked]": "string"
}

これを実装する前に、これは何を意味するのでしょうか?

つまり、{post: {raw: ..., raw_old: ... }} という構造を指しているのでしょうか?

それとも単に {raw: "", raw_old: ""...} という形式でしょうか?

また、raw_old とは何でしょうか?各要素は JSON ボディに PUT する必要がある「文字列」としか記載されていません。

私は、ボットによって当初作成された投稿の冒頭に、別のサイトへのリンクを追加しようとしています。なお、その最初の段落をカテゴリタイトルの下に表示したいと考えており、cooked<div> 要素(カテゴリタイトルの直下に定義されているもの)で表示させる必要があります。

この説明で伝わるでしょうか?もし不明な点があれば、 clarification をお寄せください。

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:

This is also how the discourse_api gem does it:

「いいね!」 3

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.

Thanks for all your help.

There is a slight discrepancy in API Docs:

Documentation says: PUT /posts/{id}.json with payload

Content type: application/json

{
  "post[raw]": "string",
  "post[raw_old]": "string",
  "post[edit_reason]": "string",
  "post[cooked]": "string"
}

but this only works with PUT /posts/{id} and Content-Type: application/x-www-form-urlencoded.

The correct payload for PUT /posts/{id}.json should be:

Content type: application/json

{
  "post": {
      "raw": "string",
      "raw_old": "string",
      "edit_reason": "string",
      "cooked": "string"
    }
}

The raw parameter is sufficient for replacing the entire post.

「いいね!」 5

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.

本日、この件が私に割り当てられました。解除できるかもしれません :slight_smile:

いずれにしても、ドキュメントは現在正しいです: https://docs.discourse.org/#tag/Posts/operation/updatePost

「いいね!」 3