Consume Atlassian Webhook with ASP.NET WebAPI?

I have been instructed to write a service that will accept HTTP POST data from Atlassian Webhook sent from JIRA. I would like to use this service using WebAPI in 4.0 .NET platform and I am wondering how to do it. I found this resource that exposes the POST data format: JIRA Web Hosts Overview .

I think I can write a WebAPI "Post" method that accepts input as Dictionary<string, object>

, but I was hoping to map to a well-defined object instead of a goo dictionary.

I see there is a NuGet package called Atlassian.SDK which "contains utilities for interacting with Atlassian JIRA". However, the API seems to be geared more towards reading JIRA tickets, creating and updating them.

Does the Atlassian.SDK NuGet package provide the ability to use an HTTP POST sent by a Webhook in a strongly typed way instead of parsing JSON data using a .NET Dictionary?

+3


source to share


1 answer


AFAIK Atlassian.SDK doesn't support Webhook script. It supports REST API calls (query and update issues) via Linq to Jira extension and classes as you wrote.

However, I don't think you have to manually parse the JSON using the .NET Dictionary. I took some very simple steps to create a strongly typed webhook result in the ApiController.



  • I have 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 available at http://localhost:18177/

  • I have installed 2 webcams in Jira, pointing to these addresses Webhooks in Jira

  • I created a new issue in Jira and on the Requestb.in page I copied all JSON content to the clipboard found under Raw Body.

  • The main point here: I created custom classes from this JSON content. (You can do this with any tool you want like JSON2Sharp ) I personally did it with the Visual Studio Web Essentials extension. ( Edit -> Paste special -> Paste JSON as Classes

    )

  • I renamed the root to JiraWebhookObject

    and I changed the signature of the ValuesController Post method to

    public void Post([FromBody]JiraWebhookObject value)
    
          

  • Finally, I changed the description of the problem. As a result of webhook update, I got a strongly typed result in my web API controller. Strongly-typed webhook

+2


source







All Articles