Search code examples
node.jsrequestslack-apislack

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

Solution

  • 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.