Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Slack Webhook - Getting Invalid_Payload

I am attempting to set up a webhook to Slack, but am getting an Error message of "Invalid_Payload"

I've looked through Stack, Slack, and Github... but cant' find the answer I seek.

"CustomLink" in there for privacy, actual link is begin used.

CODE:

var request = require('request')

var webhook = "https://hooks.slack.com/services/CUSTOMLINK"

var payload={"text":"This is via an integration from Me - It is a test"}

request.post({url: webhook, payload: payload}, function(err, res){
    if(err){console.log(err)}
    if(res){console.log(res.body)}
})

ERROR:

 invalid_payload
like image 674
KJ Carlson Avatar asked Oct 07 '16 20:10

KJ Carlson


People also ask

Are Slack Webhooks sensitive?

The webhook only accepts data, and thus alone cannot expose sensitive data to third parties.

Is Slack webhook a secret?

Your webhook URL contains a secret. Don't share it online, including via public version control repositories. Slack actively searches out and revokes leaked secrets.

Is it possible to post files to Slack using the incoming webhook?

While you can use legacy incoming webhooks to post messages, they do not have access to interactive messages features. To make your messages interactive, you'll need to create an incoming webhook with a Slack app instead. Please note: it's not possible to send files via webhook.


2 Answers

This worked for me

var payload = {"text":"Message to be sent"}
payload = JSON.stringify(payload);

request.post({url: url, body: payload},function(err,data){
    console.log(data.body);
})
like image 112
Kaustav Ganguli Avatar answered Oct 17 '22 16:10

Kaustav Ganguli


var payload= {"text":"This is via an integration from Me - It is a test"}
payload = JSON.stringify(payload)

I had forgot to stringify the JSON I was creating. Stupid Me.

like image 38
KJ Carlson Avatar answered Oct 17 '22 15:10

KJ Carlson