문서(docs)를 따랐는데, 제목만 업데이트되고 본문은 업데이트되지 않습니다.
제 코드 (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: "new body(doesn't apply)"
}
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 )
2
코드를 보고 추측해 본 것인데, post_id 대신 topic_id를 사용하고 있어서 그런 것일지도 몰라요. Discourse에서는 첫 번째 게시물이 사실상 주제(topic)이니까요?
Canapin
(Coin-coin le Canapin)
3
@Lilly가 맞아요.
토픽은 제목, 카테고리, 태그 등의 속성으로 정의됩니다.
하지만 콘텐츠는 게시물에 속합니다.
제목과 콘텐츠를 모두 업데이트하려면 2개의 요청이 필요합니다.
-
토픽에 대한 PUT 요청
-
첫 번째 게시물에 대한 PUT 요청. 게시물의 ID는 페이지의 HTML 코드에서 찾을 수 있습니다. <article> 요소의 data-post-id 속성을 확인하세요.
예:
<article id="post_2" aria-label="post #2 by @Lilly" role="region" data-post-id="1288311" data-
topic-id="264640" data-user-id="127856" class="boxed onscreen-post">
와, 맞아요. 잘 작동하네요 
그리고 Discourse API를 사용하여 주제(topic)의 첫 번째 게시물 ID를 가져오는 방법을 알아냈습니다:
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;
}
감사드리고요, @Lilly 