Slack: Webhooks for slack integration is throwing 400 error

Created on 19 Jan 2019  路  14Comments  路  Source: integrations/slack

Most helpful comment

I can post to webhook with curl in terminal. 400 error in github

Headers
Access-Control-Allow-Origin: *
Connection: keep-alive
Content-Length: 7
Content-Type: text/html
Date: Wed, 29 Jan 2020 04:49:34 GMT
Referrer-Policy: no-referrer
Server: Apache
Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
Transfer-Encoding: chunked
Vary: Accept-Encoding
Via: 1.1 05a90e634e0872685ad69ee9a4e0eba5.cloudfront.net (CloudFront)
X-Amz-Cf-Id: df1Lkn1oT1mINwavBqDQI_nyNYC0bnoYlhBnxQWixA0fLAXZxzwnzg==
X-Amz-Cf-Pop: IAD89-C2
X-Cache: Error from cloudfront
X-Frame-Options: SAMEORIGIN
X-Slack-Backend: h
X-Via: haproxy-www-a57w
Body
no_text

All 14 comments

Thanks for opening this issue! If you would like to help implement an improvement, read more about contributing and consider submitting a pull request.

Not sure what you mean

I am seeing the same thing actually from our internal webhooks, I think it's slack side.

Any update?
The same issue when we hit from BB

I got the same, slack returns

_Response headers:
Content-Type: text/html
Transfer-Encoding: chunked
Connection: close
Date: Tue, 28 May 2019 02:28:21 GMT
Server: Apache
Vary: Accept-Encoding
Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
Referrer-Policy: no-referrer
X-Frame-Options: SAMEORIGIN
Access-Control-Allow-Origin: *
X-Via: haproxy-www-icn9
X-Cache: Error from cloudfront
Via: 1.1 107e6221a3918b7fdc812d78ae3e5448.cloudfront.net (CloudFront)
Response body:_

Same here

If you're using GitHub Enterprise, you need to use the Slack app called "GitHub Notifications (Legacy)"

Same here

I can post to webhook with curl in terminal. 400 error in github

Headers
Access-Control-Allow-Origin: *
Connection: keep-alive
Content-Length: 7
Content-Type: text/html
Date: Wed, 29 Jan 2020 04:49:34 GMT
Referrer-Policy: no-referrer
Server: Apache
Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
Transfer-Encoding: chunked
Vary: Accept-Encoding
Via: 1.1 05a90e634e0872685ad69ee9a4e0eba5.cloudfront.net (CloudFront)
X-Amz-Cf-Id: df1Lkn1oT1mINwavBqDQI_nyNYC0bnoYlhBnxQWixA0fLAXZxzwnzg==
X-Amz-Cf-Pop: IAD89-C2
X-Cache: Error from cloudfront
X-Frame-Options: SAMEORIGIN
X-Slack-Backend: h
X-Via: haproxy-www-a57w
Body
no_text

@gimenete @wilhelmklopp ping? Any idea where to start?

I can post to webhook with curl in terminal. 400 error in github

Headers
Access-Control-Allow-Origin: *
Connection: keep-alive
Content-Length: 7
Content-Type: text/html
Date: Wed, 29 Jan 2020 04:49:34 GMT
Referrer-Policy: no-referrer
Server: Apache
Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
Transfer-Encoding: chunked
Vary: Accept-Encoding
Via: 1.1 05a90e634e0872685ad69ee9a4e0eba5.cloudfront.net (CloudFront)
X-Amz-Cf-Id: df1Lkn1oT1mINwavBqDQI_nyNYC0bnoYlhBnxQWixA0fLAXZxzwnzg==
X-Amz-Cf-Pop: IAD89-C2
X-Cache: Error from cloudfront
X-Frame-Options: SAMEORIGIN
X-Slack-Backend: h
X-Via: haproxy-www-a57w
Body
no_text

As far as I know, Slack requires {"text": "Your message here" } in your payload.
Check your Recent Deliveries in Github, and see one of the request payload, you will not see any attribute called text. That's just how Github works.

I have the same problem and I don't know how to work this out, too.

I would lean to just using Github App in Slack.

Man... from 2019-now 2021 still no option for that ?
i have some issues.. i dont know how to solved it

same here

Here is a proxy workaround - very simple one

you can test it with https://www.offline.news/api/proxy/webhook/github2slack/SLACK_KEY

(the slack key is in the form of A/B/C)

var https = require('https');

// const request = require('request');

var bodyParser = require('body-parser');

const app = express()

// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }))

// parse application/json
app.use(bodyParser.json())

// ...

app.post('/api/proxy/webhook/github2slack/:slackkeyA/:slackkeyB/:slackkeyC', (req, res) => {
  const slackkeyA = req.params.slackkeyA;
  const slackkeyB = req.params.slackkeyB;
  const slackkeyC = req.params.slackkeyC;

  const data = JSON.stringify({
    text: `PR ${req.body.pull_request.state} by ${req.body.pull_request.user.login}: ${req.body.pull_request.title} - url:${req.body.pull_request.url}`
  })

  const options = {
    hostname: 'hooks.slack.com',
    port: 443,
    path: `/services/${slackkeyA}/${slackkeyB}/${slackkeyC}`,
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'Content-Length': data.length
    }
  }

  const req2 = https.request(options, res2 => {
    res2.on('data', d => {
      res.setHeader('Content-Type', 'application/json');
      res.send(d);
    })
  })

  req2.on('error', error => {
    console.error(error)
  })

  req2.write(data)
  req2.end()
});

Was this page helpful?
0 / 5 - 0 ratings