slack icon indicating copy to clipboard operation
slack copied to clipboard

Webhooks for slack integration is throwing 400 error

Open SVDileepKumar opened this issue 6 years ago • 19 comments

SVDileepKumar avatar Jan 19 '19 19:01 SVDileepKumar

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

welcome[bot] avatar Jan 19 '19 19:01 welcome[bot]

Not sure what you mean

gimenete avatar Jan 31 '19 16:01 gimenete

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

vccs avatar Feb 15 '19 17:02 vccs

Any update? The same issue when we hit from BB

kaarolch avatar May 16 '19 12:05 kaarolch

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:

JnMik avatar May 28 '19 02:05 JnMik

Same here

TheNaderio avatar Jun 17 '19 09:06 TheNaderio

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

dburtonDRW avatar Jun 21 '19 16:06 dburtonDRW

Same here

Mahlue-Goodson avatar Nov 11 '19 12:11 Mahlue-Goodson

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

ajahansh avatar Jan 29 '20 05:01 ajahansh

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

pombredanne avatar Mar 07 '20 00:03 pombredanne

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.

kamatisdev avatar May 01 '20 14:05 kamatisdev

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

abersofttechnologies avatar Jan 23 '21 02:01 abersofttechnologies

same here

nagaoyuriko avatar Feb 13 '21 02:02 nagaoyuriko

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()
});

edisonnica avatar Mar 13 '21 19:03 edisonnica

2022/06/04 still not working.

guinan34 avatar Jun 02 '22 07:06 guinan34

Solution:

  1. Remove "Content-Type" header
  2. body should be a stringified object with one key "text" and a string value body: JSON.stringify({ text: 'some string...' })

asafd-artlist avatar Jun 03 '22 13:06 asafd-artlist

Use integrations instead of a custom webhook, they have one specifically for slack that will send the text property on the body

kroehrs avatar Aug 24 '22 17:08 kroehrs

2023/05/27 still not working.

Kenini1805 avatar May 27 '23 09:05 Kenini1805

Still not working same error. Body missing_text_or_fallback_or_attachments

zshansiddiquieBCIndia avatar Aug 04 '23 03:08 zshansiddiquieBCIndia

Still same issue

tanvirrb avatar Apr 30 '24 16:04 tanvirrb