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.
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.
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.
Running the tests and adding some watches I could easily validate I was on my way!
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.
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.
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.
So lets check the Team Room for our message! Voila there it is!
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!
One Reply to “Utilize the TFS Team Room REST API”