我确实遵循了 文档,但是,它只更新了主题的标题,而没有更新正文。
我的代码 (Javascript):
async function updateDiscourseTopic(topic_id) {
const Discourse_API_Key = "Discourse_API_Key";
const url = `https://discourse.mysite.com/t/-/${topic_id}.json`;
const payload = {
title: 'session_1',
raw: "新的正文(不适用)"
}
const response = await fetch(url, {
method: 'PUT',
headers: {
"Api-Key": Discourse_API_Key,
"Api-Username": "system",
"Content-Type": "application/json",
},
body: JSON.stringify(payload)
});
}
Lilly
(Lillian Louis)
2
只是根据代码猜测,但也许是因为你使用了 topic_id 而不是 post_id?因为在 Discourse 中,第一个帖子或多或少就是主题?
3 个赞
Wow,you are right, it works 
And I figured out how to retrieve the ID of the first post in a topic using the Discourse API:
async function getFirstPostIdFromOnetopic(topic_id) {
const Discourse_API_Key = "Discourse_API_Key";
const url = `https://discourse.mysite.com/t/${topic_id}/posts.json`;
const response = await fetch(url, {
method: 'GET',
headers: {
"Api-Key": Discourse_API_Key,
"Api-Username": "system",
"Content-Type": "application/json",
}
});
const data = await response.json();
const firstPostId = data.post_stream.posts[0].id;
return firstPostId;
}
Thank you and @Lilly 
3 个赞
system
(system)
关闭
5
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.