APIを使用して新しい投稿を追加できません

APIを使用してDiscourseフォーラムに新しいトピック投稿を追加できません。私のコードは次のとおりです。

function postComment(topicId, comment) {
  const url = `${DISCOURSE_API_URL}/t/${topicId}/posts.json`; // このURLが正しいことを確認してください
  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, // 完全なエラーレスポンスをキャプチャするため
  };

  try {
    const response = UrlFetchApp.fetch(url, options);
    const jsonResponse = JSON.parse(response.getContentText());

    // デバッグのためにレスポンスをログに記録します
    Logger.log(`Response Code: ${response.getResponseCode()}`);
    Logger.log(`Response Body: ${JSON.stringify(jsonResponse, null, 2)}`);

    // 投稿が成功したかどうかを確認します
    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; // APIレスポンスを返します
  } catch (error) {
    Logger.log(`Error posting comment: ${error}`);
    return null; // エラーの場合はnullを返します
  }
}

次のレスポンスが得られます。

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

「いいね!」 2