SLACKにJSONメッセージを送信するには?

SLACKにJSONメッセージを送信するには?

次のJSONファイルがあります。

{
  "blocks": [
    {
      "type": "section",
      "text": {
        "type": "mrkdwn",
        "text": "Success: ondrejdolezal93's workflow (<https://circleci.com/api/v1.1/project/github/integromat/docker-db-updater/628|build>) in <https://app.circleci.com/pipelines/github/integromat/docker-db-updater%7Cintegromat/docker-db-updater> (<https://app.circleci.com/pipelines/github/integromat/docker-db-updater?branch=main%7Cmain>)\n- Fix update version (<https://github.com/integromat/docker-db-updater/commit/9a5b8d61a5c79dabbb2a47bb68b33748034986aa%7C9a5b8d6> by ondrejdolezal93)"
      }
    }
  ]
}

Slack Webhookを使用してcurl

私のコマンドは次のとおりです。

curl -X POST -H 'Content-type: application/json' --data @message.json $SLACK_WEBHOOK_URL

カールの答えは次のとおりです。no_text

私は何が間違っていましたか? JSONはSlack APIドキュメントに従ってフォーマットされています。

ベストアンサー1

Slack API ドキュメントでは、JSON でエンコードされた本文を送信すると、次のようになると明示されています。〜しなければならないHTTPヘッダーにAPIトークンを送信しますAuthorization。あなたはこれをしませんでした。

curlクエリの例はドキュメントに提供されています(インデント、インラインJSONドキュメントをファイルへの参照に置き換え、URLを引用して変更されます)。

curl -X POST \
    -H 'Authorization: Bearer xoxb-1234-56789abcdefghijklmnop' \
    -H 'Content-type: application/json' \
    --data @message.json \
    'https://slack.com/api/chat.postMessage'

ここでAPIドキュメントをご覧ください。https://api.slack.com/web

おすすめ記事