I've been tasked with writing a service that will accept the HTTP POST data from an Atlassian Webhook sent from JIRA. I'd like to consume the service using WebAPI in the 4.0 .NET framework and I'm wondering how to do this. I found this resource which uncovers the format of the POST data: JIRA Webhooks Overview.
I think that I can write a WebAPI "Post" method that accepts the input as a Dictionary<string, object>
, but I was hoping to map to a well-defined object instead of a Dictionary of goo.
I see that there is a NuGet package called Atlassian.SDK which "Contains utilities for interacting with Atlassian JIRA". However, it looks as though the API is geared more toward reading JIRA tickets, creating and updating them.
Does the Atlassian.SDK NuGet package allow for consuming the HTTP POST sent by a Webhook in a strongly-typed manner instead of parsing through the JSON data using a .NET Dictionary?
AFAIK the Atlassian.SDK doesn't support the Webhook scenario. It supports REST API calls (query and update issues) via Linq to Jira extension and classes, as you wrote.
However, I don't think that you should manually parse the JSON using .NET Dictionary. I have made some very easy steps to produce a strongly-typed webhook result in an ApiController.
I set up a temporary request container in Requestb.in (http://requestb.in/1g9lg8y1
)
I created a new ASP.NET MVC Application with Web API, when I started it in the browser, it was accessible on http://localhost:18177/
I set up 2 webhooks in Jira pointing to these addresses
I created a new issue in Jira, and in the Requestb.in page I copied the whole JSON content to the clipboard found in raw body section.
The main point is here: I created custom classes from this JSON content. (You can do this with any tool you want, e.g. JSON2Sharp), personally I did it with the Visual Studio's Web Essentials extension. (Edit -> Paste special -> Paste JSON as Classes
)
I renamed the root to JiraWebhookObject
, and I modified the signature of the ValuesController's Post method to
public void Post([FromBody]JiraWebhookObject value)
Finally I modified the issue's summary. As a result of the updated webhook, I got the strongly-typed result in my Web API Controller.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With