Posting a message to a room for CURL post using hipchat v2

Hi,

I am trying to post information from a file to a room but keep getting this error.

The request body cannot be parsed as valid JSON. 

curl -H 'Content-Type: application/json' \
-d '{"color":"green","message": "'"$MESSAGE"'","notify":true,"message_format":"text"}'

Any idea why this would be happening ?

 

Thanks,

Victor

3 answers

This widget could not be displayed.

Hi VIctor,

$MESSAGE should be enclosed in {{"}} rather than {{'}}.

I use http://jsonlint.com/ to validate json, helps quite a bit.

This widget could not be displayed.

Hi VIctor,

$MESSAGE should be enclosed in " rather than '.

I use http://jsonlint.com/ to validate json, helps quite a bit.

This widget could not be displayed.

Hi,

It's strange right now if I have 

$MESSAGE = "TEST" it works fine, but if I have multi-line file it doesn't work.

 

Will try your solution of {{'}} for the text.

 

Thanks,

Victor

It is " vs ' . You need to use ". I didn't format it correctly in my answer.

Hi,

I still can't get this work with a multi-line message, do you have an example of this working ? Or do I need to send the messages to HipChat one line at a time ?

 

Thanks,

Victor

New line is an invalid character in a JSON string. You need to substitute it with '\n' to have the new line inside a message.

E.g:

curl -d '{"color":"green","message":"My first notification \n (yey)","notify":false,"message_format":"text"}' -H 'Content-Type: application/json'

 

 

Hello,

I am trying to take a html file that has list of  files changes and send it to HipChat in a notification. 

Is there a way we can have a call so you can help me with this. 

 

I am getting the below error. 

{
  "error": {
    "code": 400,
    "message": "The request body cannot be parsed as valid JSON: Unterminated string starting at: line 1 column 28 (char 27)",
    "type": "Bad Request"
  }

 

 

Thanks,

Victor

New to hipchat... where do we create the curl commands? is that command line or within your programming language?

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Aug 10, 2018 in Hipchat

What should I think about when migrating HipChat to Slack?

...from the beginning. We have built up a lot of content in HipChat, with it being a core tool in our distributed company model. While it is true that we didn’t need to move to Slack immediately, we felt it...

397 views 1 10
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