Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

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

victsant8 January 15, 2016

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
Atlassian Team members are employees working across the company in a wide variety of roles.
January 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
victsant8 January 17, 2016

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
Atlassian Team members are employees working across the company in a wide variety of roles.
January 17, 2016

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

victsant8 January 18, 2016

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
Atlassian Team members are employees working across the company in a wide variety of roles.
January 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'

 

 

victsant8 January 20, 2016

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

Trevor Schmidt September 6, 2017

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

0 votes
Anatoli
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 17, 2016

Hi VIctor,

$MESSAGE should be enclosed in " rather than '.

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

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events