Sending a Card to a HipChat room always returns 400: "Value {value!r} is not of type {expected_type!r}"

This question is in reference to Atlassian Developer Documentation: Sending Messages

No matter how I change the JSON I always get the response:

"Value {value!r} is not of type {expected_type!r}"

But as you can see, the placeholders are not replaced by what actually is wrong. No matter what I change or remove, the error remains the same. If I just send a message to the room, everything works fine. The generated JSON looks like this:

{
  "id": "8c50988a-ef54-4884-ad67-b86b41e1c366", 
  "style": "application", 
  "title": "Notify Me Here", 
  "format": "medium", 
  "description": "You've been notified", 
  "url": "http://www.cnn.com", 
  "attributes": [{
    "label": "Nick", 
    "value": {"style": "lozenge-complete", 
              "label": "FancyBot"}
          }
        ], 
  "icon": {"url": "http://bit.ly/1Qrfs1M"}
}

3 answers

1 accepted

Ok, I'm a fool! I admit it. The thing about the REST Client App getting things at least half-way right was bugging me. So while having had another 30min. time to spend on this, I looked at the request data that I was actually sending and figured that the content-type header 

{"Content-Type":"application/json"}

 wasn't added and the body data not properly converted to json (as I've nicely done that in the wrong location, I should wear my glasses more often . . .). After I fixed that, it worked.

@Anatoli Kazatchkov thanks for looking into this. This is fixed now.

0 vote

I have just tested your JSON and it worked as expected for me:

image2016-8-18 15:34:43.png

Are you setting the card field of the message to the JSON you listed? The whole message

{
"message": "fallback message for old clients that cannot render cards",
"card": {....}
}

The whole format can be found here.

Hello @Anatoli Kazatchkov

thanks for the response. The whole body would look like this:

 

{
  "message_format"="text",
  "color": "green",
  "notify": "true", 
  "card": {
    "id": "9784aa87-c950-41c3-b164-4a4f4aa76d40",
    "icon": {
      "url": "http://bit.ly/1Qrfs1M"},
      "style": "application",
      "format": "medium",
      "attributes": [{
        "value": {
          "style": "lozenge-complete",
          "label": "FancyBot"},
        "label": "Nick"
      }],
      "title": "Maniac",
      "description": {
        "value": "You\'re a Maniac for Python",
        "format": "html"}},
  "message": "who@this_domain.com/Psi+ wrote:\nJava?"
}

After removing the three other parameters:

"message_format"="text",
"color": "green",
"notify": "true"

The room will render the icon as an image but post the rest of the body as text. So the message is accepted now, but just not as a card. And only if I use a REST Client App for testing purposes. The code itself will send a body that still is rejected. But there is a phrase in my language that loosely translates to "Those who can read \[Error Messages\] have a clear advantage" . . .

The actual error message I get is:

"message": "Value u'attributes' for field 'card' is not of type [{'type': 'null'}, ...

Now that's strange . . .

UPDATE: I figured that the message is random. If I restart the application it's just another value for the field 'card' that's dubbed not of type. E.g.:

 

"Value u'id' for field 'card' is not of type [{'type': 'null'}

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

...able to use the clients After a bunch of testing (rooms, memberships, check for private message history, and most importantly - the custom emoticons!) nearly everything was looking as we needed, however...

441 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