안녕하세요. Discourse 포럼에서 API를 사용하여 주제에 새 게시물을 추가할 수 없습니다. 제 코드는 다음과 같습니다:
function postComment(topicId, comment) {
const url = `${DISCOURSE_API_URL}/t/${topicId}/posts.json`; // Ensure this URL is correct
Logger.log(`Posting to URL: ${url}`);
const headers = {
"Api-Key": DISCOURSE_API_KEY,
"Api-Username": DISCOURSE_API_USERNAME
};
const payload = {
post: {
topic_id: topicId,
raw: comment
},
};
const options = {
method: "post",
contentType: "application/json",
headers: headers,
payload: JSON.stringify(payload),
muteHttpExceptions: true, // To capture the full error response
};
try {
const response = UrlFetchApp.fetch(url, options);
const jsonResponse = JSON.parse(response.getContentText());
// Log the response for debugging
Logger.log(`Response Code: ${response.getResponseCode()}`);
Logger.log(`Response Body: ${JSON.stringify(jsonResponse, null, 2)}`);
// Check if the posting was successful
if (response.getResponseCode() === 200) {
Logger.log(`Posted comment successfully: ${JSON.stringify(jsonResponse, null, 2)}`);
} else {
Logger.log(`Failed to post comment: ${JSON.stringify(jsonResponse, null, 2)}`);
}
return jsonResponse; // Return the API response
} catch (error) {
Logger.log(`Error posting comment: ${error}`);
return null; // Return null on error
}
}
다음과 같은 응답을 받고 있습니다:
Info
Response Code: 404
3:35:29 PM
Info
Response Body: {
"errors": [
"The requested URL or resource could not be found."
],
"error_type": "not_found"
}
포럼의 주제가 존재하며 포럼 웹사이트에서 직접 게시물을 작성할 수 있음에도 불구하고 이 문제가 발생합니다.
도움을 부탁드립니다.