使用 API 更新帖子内容时出现 500 或 400 错误

我试图使用 API 更新帖子的内容。Discourse API Docs 上的文档提到我应该使用 PUT /posts/:id.json 并发送 post[raw] 作为请求体。

但这导致了 400 错误,并返回以下信息:

errors: [ 'param is missing or the value is empty: post' ]

该错误抱怨缺少名为 post 的参数,但在我的 HTTP 请求中将 post[raw] 替换为 post 后,却返回了 500 内部服务器错误。

帖子内容仅为“编辑后的评论”,所以我认为这与内容无关。

我是否遗漏了什么?API 文档是否已过时?

我正在 https://forums.balena.io 上运行一个云实例。不确定 Discourse 的版本。

I just realised I was passing a topic id instead of a post id to the API, but the problem still persists. I’m trying to update post 34816, assuming you have access to the cloud instance:

PUT https://forums.balena.io/posts/34816.json

With body:

{
    "post": "Edited comment"
}

And that still results in 500.

Why is my post being flagged as spam? Is this not the right place to submit bugs?

Turns out it works fine if I pass raw instead of post in the request body. The docs could probably be clearer about that :slight_smile:

4 个赞

Glad you got it figured out! I’ve got a bunch of topics that are me taking to myself.

Mostly these are the docs, and they are continually updated: How to reverse engineer the Discourse API :wink:

I generally forget that there are any docs besides just seeing how it works in the browser development tools.

5 个赞