API를 사용하여 새 게시물을 추가할 수 없음

안녕하세요. 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"
}

포럼의 주제가 존재하며 포럼 웹사이트에서 직접 게시물을 작성할 수 있음에도 불구하고 이 문제가 발생합니다.

도움을 부탁드립니다.

404 오류는 일반적으로 API 키가 잘못되었거나 올바르게 전달되지 않고 있음을 의미합니다.

실제로 잘못된 경로를 사용하고 있는 것이 아니라면요. 게시물을 위해 Discourse API를 역설계하면, 사용된 경로가 그 경로인가요?

이 경로를 사용하고 있습니다: ${DISCOURSE_API_URL}/t/${topicId}/posts.json
여기서 DISCOURSE_API_URL = "https://community.xxxxxxxxxxx.com"입니다.

API를 통해 주제에 답글을 작성하는 URL은 /posts.json이라고 생각합니다. 새 주제를 생성할 때와 달리, 답글을 생성할 때는 topic_id가 필수 파라미터입니다.

상세한 내용은 여기에서 확인할 수 있습니다: Discourse API Docs. 또한 사이트의 UI를 통해 주제에 답글을 작성한 후 브라우저 웹 인스펙터의 “network” 섹션에서 설정된 RequestURL을 확인하는 방법도 있습니다.