Utilize the TFS Team Room REST API

Here we go, part 1 of the announced series on Release Management + PowerShell + TFS TeamRoom API!

Based on the publicly available information in Brian Harry’s post on the Team Rooms API (http://blogs.msdn.com/b/bharry/archive/2013/07/22/rest-api-for-team-rooms.aspx) I decided that I wanted to add messages from Release Management to a particular Team Room.

Disclaimer: The Team Room API is subject to change, this might therefor not work in the future, and this code is just intended for demo purposes, so if you reuse it is at your own risk.

To get started I wanted a quick and easy way to be calling the Team Room API for this I created a service application to encapsulate the Team Room API calls. I had to figure out what the suggested route was to actually talk to the REST API. Popular REST frameworks, encapsulating the actual JSON plumbing, seem to be RestSharp (http://restsharp.org/) and NewtonSoft JSON (http://www.nuget.org/packages/newtonsoft.json/). Both can be included in your solution as NuGet packages.

Wanting to post a message I needed a TeamRoomService. This service needs a method, LoadTeamRooms(). This method uses the RestClient Object to call the Team Room API. While using the API the Team Project needs to enable Alternate Credentials. See the following URLS for more information on the neccesarry actions to enable this.

http://blogs.msdn.com/b/buckh/archive/2013/01/07/how-to-connect-to-tf-service-without-a-prompt-for-liveid-credentials.aspx

http://social.msdn.microsoft.com/Forums/vstudio/en-US/96aa6738-6f01-4015-8c59-25215cc84897/enable-alternative-credentials

The LoadTeamRooms method lists all Team Rooms available. As you can see it requires some parameters to be able to connect to TFS. JSONConvert is used to parse the received Team Room API results.

P1_LoadTeamRooms

Load Team Rooms

Using a Test Project I could easily get the properties from a configuration file.  My TeamRoomService accepts the properties. The TeamRoomServiceGetTeamRooms() method gets the rooms. The results are then places in an object that allows me to access them more easily.

P1_CreateTeamRoomService

Create Team Room Service

Running the tests and adding some watches I could easily validate I was on my way!

P1_DebugTeamRoom

Debug Team Room

Being able to get the available Team Rooms I wanted to be able to find a specific one, re-using my earlier code this was quite simple. Please note my unit test has an if that validates my findings on either on-premise TFS or Visual Studio Online TFS instances.

P1_FindTeamRoom

Find Team Room

In both scenarios this enabled me to find a specific Team Room. Having found the Team Room ID, I was able to use the PostMessage method on the Team Room API.

P1_PostMessage

Post Message

This calls the Post Message method of my TeamRoomService. This method calls the Team Room API Service to post a message. When successful it returns the ID of the posted message.

P1_PostMessageAPI

Post Message API

So lets check the Team Room for our message! Voila there it is!

Team Room Message

Having you walked through the basis of my components we are able to utilize the Team Room API to post a message. In the next part I will take you to the next phase encapsulate this TeamRoomService in a PowerShell Commandlet.

Note: The source code for this will be posted as a complete download with the latest post of this series so you get a full working solution at once!

Advertisements

One thought on “Utilize the TFS Team Room REST API

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s