How to send Message to Room in Hipchat using PHP Code without using any third-party library?

I am using below code:

$data = array(
"color" => "gray",
"message_format" => "text",
"message" => "My First Notify"
$url_send ="https://{hostname}/v2/room/{room_id}/notification?auth_token={keys}";
$str_data = json_encode($data);

function sendPostData($url, $post)
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS,$post);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Content-Length: ' . strlen($post)));
$result = curl_exec($ch);
return $result;
$res = sendPostData($url_send, $str_data);
if($res != false)
echo "Response: ".$res;


If anybody know how to solve let me know. Thanks in advance.

1 answer

0 vote

It looks like you need the Authorization header with your token:

If that doesn't help, the response data would probably be helpful in diagnosing issues. The error codes can often tell you a lot about why any given request failed:

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Mar 26, 2018 in Hipchat Data Center

Migration of Hipchat server to Data Center - a retrospective

Background While our Hipchat server environment was reliable and performing well, as a significant and growing part of our business, the need to leverage the benefits of Hipchat Data Center&nbs...

460 views 2 6
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you