Why does the HipChat webhook generate invalid JSON?

Hello,

When enabling the webhook to post the WebHookRequest to my API I am able to see the request. However when I want to parse this json request into a local object it fails since the JSON value contains semicolons.

An example of a request sent from HipChat to my API:

{ "event": "room_message", "item": { "message": { "date": "2015-07-09T16:06:52.039929+02:00", "from": { "id": 116, "links": { "self": "https://hipchat.xxxxxxxxx.com/v2/user/116"; }, "mention_name": "JosKrause", "name": "Jos Krause" }, "id": "xxxxxxxxx", "mentions": [], "message": "/jira create test", "type": "message" }, "room": { "id": 98, "links": { "participants": "https://hipchat.xxxxxxxxx.com/v2/room/98/participant";, "self": "https://hipchat.xxxxxxxxx.com/v2/room/98";, "webhooks": "https://hipchat.xxxxxxxxx.com/v2/room/98/webhook"; }, "name": "HipChat Plugin TestLab" } }, "oauth_client_id": "xxxxxxxxx", "webhook_id": 7 }

As you can see after the URL values a semicolon is appended after the string value has been closed off.

This is completely preventing me from using the webhook.

Could you tell me what is going on please?

3 answers

1 accepted

This widget could not be displayed.

I am directly returning the parameter containing the JSON body as the result of the POST call.

public HttpResponseMessage MyMethod(object json) {
    return new HttpResponseMessage("OK", json);
}

So that should copy it back as-is.

As per suggestion I have created an interface ( IHipChatRequest ) that resembles the properties available on the JSON-object and after casting it seems to resolve all properties fine and makes the semi-colon issue to disappear:

public HttpResponseMessage MyMethod([FromBody]IHipChatRequest json) {
    return new HttpResponseMessage("OK", json);
}

I am not sure why the "raw" json contains that semi-colon and why it disappears after the [FromBody] cast to the interface, I am going to accept it's part of the educational process implementing this webhook; after all I don't have to understand everything in order to create something I do understand =]

Many thanks though for thinking along and providing helpful feedback!

This widget could not be displayed.

Thanks for raising it Jos. While we are investigating the problem you can run a s/";/" substitution on json string before creating a json object.

This widget could not be displayed.

Jos,

I was unable to reproduce this behaviour. The json sent to my webhook does not contain any semi-colons and looks fine:

{"event": "room_message", "item": {"message": {"date": "2015-07-10T00:24:58.419157+00:00", "from": {"id": 1, "links": {"self": "https://xxxx.hipchat.com/v2/user/1"}, "mention_name": "Conor", "name": "Conor"}, "id": "7bd37557-a4d6-49f5-b43b-c852901f23eb", "mentions": [], "message": "test", "type": "message"}, "room": {"id": 1, "links": {"participants": "https://xxxx.hipchat.com/v2/room/1/participant", "self": "https://xxxx.hipchat.com/v2/room/1", "webhooks": "https://xxxx.hipchat.com/v2/room/1/webhook"}, "name": "Atlassian"}}, "oauth_client_id": "xxxxxxxxxxx", "webhook_id": 2}

Could you give me some additional information on your setup? What is implementing your API?

 

I am using WebAPI 2.1 using C#; I am returning the posted object as a HttpResponseMessage so I can see what information is exactly being sent to the post method.

I am also using the JSON.NET v7 library to parse and produce the JSON itself.

Thanks Jos. I'm not personally familiar with the C# stack. It would be good to verify the json at the wire level before it enters your server. One possibility would be to run a small local logging proxy and see what is going to and from your code. Alternatively the workaround that Anatoli mentioned may be sufficient to get you up and running.

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
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...

243 views 1 9
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