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

Philipp Sonntag August 17, 2016

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

1 vote
Answer accepted
Philipp Sonntag August 18, 2016

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 votes
Philipp Sonntag August 17, 2016

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'}
0 votes
Anatoli
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 17, 2016

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.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events