LoginSignup
1
1

More than 3 years have passed since last update.

Vuejs + axios + Slack Incoming WebHooks

Posted at

フロントのJS(axios)からIncoming WebHooksにリクエストするさいのメモ
CORSで怒られてたところ、AuthorizationとContent-Typeヘッダーを削除することで上手くいった。


    var params = {
      'blocks': [{
        'type': 'divider'
      }, {
        'type': 'section',
        'text': {
          'type': 'mrkdwn',
          'text': 'message'
        }
      }]
    }
    async function slack (payload) {
      var WEBHOOK_URL = 'https://hooks.slack.com/services/*******/*******/*********'
      const res = await axios.post(WEBHOOK_URL, JSON.stringify(payload), {
        withCredentials: false,
        transformRequest: [(data, headers) => {
          delete headers.common.Authorization
          delete headers.post['Content-Type']
          return data
        }]
      })
      return res.data
    }

    slack(params).then(console.log)
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1