Integrate your on-premise ticket system with Visual Studio Team Services (fka VS Online)

There is a lot going on in the TFS/VSTS world. I hear more and more customers talking about the move to VSTS and I think this is a very good trend. Many scenarios that were showstoppers before are in place on VSTS and some scenarios are coming on short –term. To get a good overview of what’s coming up you can always check the feature timeline that the team posts.

What I hear a lot is that customers created integrations from their on-prem systems (for example a ticketing system) to TFS using the ISubscriber or Server plugin mechanism. I even write a few myself. They are wondering how they can link their On-Prem system to Visual Studio Team Services. I dove a little in to this matter and there is actually a pretty awesome solution for that, that is available already.

The features I am talking about are ServiceHooks and the REST Api’s for VSO. The idea is pretty simple. For the On-Prem To VSTS connection it is fairly straightforward. You just call the REST API and you are good. A simple program will do for that and you can take a look at the RestSharp libraries to have great support within C#.

 

From VSTS To On-Prem, it involves some more steps which I will explain a bit more. Basically it involves the following steps.

Create a ServiceHook calling this public EndPoint

First I will show you how to create and EndPoint. This is also documented on MSDN very neatly, but still.

 

Navigate to the admin pages of your VSTS project

SNAGHTML6a3673d

 

Then on the ServiceHooks page create a new Webhook

SNAGHTMLaab2007

Configure your webhook, to react on the Work Item Updated event

image

Then configure the URL and other properties of your call. Because we still do not have an endpoint, you can use the website http://requestb.in to generate a Test EndPoint which you can use. Use this URL to create a temporary request. After this, hit the Test button to see what will be sent over the line.

image

On the Test page, go to the Request Tab, and copy the contents JSON. This is the object that will be sent to our On-Prem service

image

 

 

Create a public website with a REST endpoint that is able to receive JSON

Now it is time to create a WebAPI Web Application that is able to receive this JSON. For this, start a new Visual Studio Project and choose the Empty Web template with WebAPI. .

image

Within the [Models] folder create a new class (e.g. WorkItem.cs).  Take the copied JSON and select [Paste Special] from the [Edit] Menu and choose [Paste JSON as classes]

image

Now that we have our object that we can receive, it is time to implement a controller. Create an empty Controller in the [Controllers] folder and call this DefaultController. Create a Post method that receives an object of the type you created (RootObject)

public class DefaultController : ApiController
    {

        public void Post(Rootobject value)
        {
            //Implement logic here to work with the Work Item
            Debug.WriteLine(value.id);
        }
    }
 

 

Now make sure you publish your WebApi somewhere on a public EndPoint and configure your Service Hook to point to this URL and you are good to go ! Call your Url something like http://<server>/api/default. If you want to test your API, you can try the Google Chrome Extension Postman to do so. Just type in your url, paste the JSON from the ServiceHook and Test

image

 

Good luck !

Trackbacks/Pingbacks

  1. Visual Studio – Developer Top Ten for Nov 23rd, 2015 - Dmitry Lyalin - November 23, 2015

    […] Integrate your on-premise ticket system with Visual Studio Online by Rene van Osnabrugge […]

  2. Fixing JSON serialization issues when using a VSTS / TFS Service Hook | Jasper Gilhuis - May 17, 2016

    […] a Service Hook when trying to capture a changed work item. I used the following strategy (see this excellent blog post by René van Osnabrugge) to create JSON classes for a generated request. While […]

  3. Fixing JSON serialization issues when using a VSTS / TFS Service Hook | Jasper Gilhuis - May 17, 2016

    […] a Service Hook when trying to capture a changed work item. I used the following strategy (see this excellent blog post by René van Osnabrugge) to create JSON classes for a generated request. While […]

  4. Fixing JSON serialization issues when using a VSTS / TFS Service Hook | Xebia Blog - February 10, 2017

    […] a Service Hook when trying to capture a changed work item. I used the following strategy (see this excellent blog post by René van Osnabrugge) to create JSON classes for a generated request. […]