It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

1 vote
Anatoli Atlassian Team Jan 17, 2016

Hi VIctor,

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

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

0 votes
Anatoli Atlassian Team Jan 17, 2016

Hi VIctor,

$MESSAGE should be enclosed in " rather than '.

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

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

Anatoli Atlassian Team Jan 17, 2016

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

Anatoli Atlassian Team Jan 19, 2016

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
TAGS
Community showcase
Published in Hipchat

Hipchat Cloud and Stride have reached End of Life (updated)

All good things come to an end - thanks to all our customers and partners who have been along the Hipchat and Stride journey with us.  As of Feb 15th 2019, Hipchat Cloud and Stride have reached ...

35,225 views 9 8
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you