Skip to content

Instantly share code, notes, and snippets.

@finferflu
Last active October 23, 2015 19:05
Show Gist options
  • Save finferflu/e513ac90b18ebbd3cc10 to your computer and use it in GitHub Desktop.
Save finferflu/e513ac90b18ebbd3cc10 to your computer and use it in GitHub Desktop.
Sample POST to Slack API method chat.postMessage
$payload = array(
'token' => 'xxxx-xxxxxxxxx-xxxx',
'channel => 'C1234567890',
'attachments' => array(array(
'text' => "This is my post body",
'fallback' => "This is the fallback"
)));
$data_str = json_encode($payload);
curl_setopt($ch, CURLOPT_URL, 'https://slack.com/api/chat.postMessage');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_str);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_str))
);
$res = curl_exec($ch);
print_r($res);
curl_close($ch);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment