Send a notification to a HipChat room via PHP

Send a notification to a HipChat room via PHP

Before using this you need an API key. First of all, enter the room your want to sent notifications to and click “Add integrations”.

Then, choose BYO (Build your own)

Lastly, enter a name the integration is supposed to have. Click Create.

You are almost done. In the last step you receive your API key and a URL as well as a prepared cURL command to test your new integration.

Adapt the snipped below to your needs and you’re good to go. You can safely omit the file logging, it’s just for debug purposes.

$data = array(
    'color' => 'purple',
    'message' => 'Buy all ze things! (allthethings)',
    'notify' => false,
    'message_format' => 'text'
);

$ch = curl_init('https://<your_url>.hipchat.com/v2/room/<room_no>/notification?auth_token=<token>');

curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));

$res = curl_exec($ch);
curl_close($ch);

file_put_contents('hipchat_hook.log', print_r($res, true));

Leave a Reply

Your email address will not be published. Required fields are marked *

8 + 10 =