Error on sending message via incoming webhook


Unable to parse incoming data

Steps to reproduce

Use php-curl to send data via a incoming webhook
see code below

Expected behavior

Posts message into channel

Observed behavior

{"id":"web.incoming_webhook.parse.app_error","message":"Unable to parse incoming data","detailed_error":"","request_id":"9u67wozjapf53fm1xacfts8cqc","status_code":400}

Does this works for you?

# must replace the URL with the actual hook URL with proper token on it
$ch = curl_init('https://chat.url.example/hooks/token');
# its easier doing it this way because then json_encode 
# will take care of escaping or whatever else it needs to do
$payload = [
	'username' => "BOT",
	'text' => "some message test!"
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'payload=' . json_encode($payload));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_HEADER, 1);
$result = curl_exec($ch);
return $result;

Its what I use for some stuff and works just fine for me, you only need to define the channel in the payload if u want to send it to a different channel then the one u have set your hook to.

1 Like