A new API for Visual Studio Online

Brian Harry

The “big” news that I announced at TechEd this week was a new API for accessing Visual Studio Online (and, in a future release, Team Foundation Server).  This new API is based on REST, OAUTH, Json and Service Hooks – all standard web technologies broadly supported in the industry.  The API is still currently in preview while we take feedback and refine it.

The reason for the new API is we wanted to make it dramatically easier to integrate VS Online with other web based tools and to access VS Online from any mobile device – whether they are 3rd party commercial tools or custom ones you are building.  Because we’ve used the standard technologies, many integrations can be done simply by wiring up simple connections with a service like Zapier.  And all connected devices – Android, iOS, Windows and more, have great support for working with services using these protocols.

As an initial wave, we’ve worked to provide specific integrations with 18 tools/services and we’ll add more in the future.  Zapier enables basic integration with hundreds more.

image

API Documentation

As part of rolling out these new APIs we’ve created a set of web pages to document them.  The new VS Online REST, OAuth and Service Hook documentation is here: http://www.visualstudio.com/en-us/integrate/explore/explore-vso-vsi

We’ve also taken the opportunity to create a consolidated landing page for all our Visual Studio, Team Foundation Server and Visual Studio Online content here: http://integrate.visualstudio.com

The docs have both good conceptual content and super simple API reference material like this section on how to get a work item with REST:

image

To experiment with it, many of the APIs can be exercised directly from your browser.  For instance, if I browse to https://minka.visualstudio.com/defaultcollection/_apis/wit/workitems/73 (minka is my personal account), I get something that looks like this. The precise output format you get depends on what browser you use and what plugins you have installed but the content is the same regardless.

image

… I’m not going to show the whole thing because it’s pretty big 🙂

The docs also have some simple samples and we’re busy working on more.  Here’s one for C#:

public static async void GetBuilds()
{
    try
    {
        var username = "username";
        var password = "password";
        using (HttpClient client = new HttpClient())
        {
            client.DefaultRequestHeaders.Accept.Add(
                new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",
                Convert.ToBase64String(
                    System.Text.ASCIIEncoding.ASCII.GetBytes(
                        string.Format("{0}:{1}", username, password))));
            using (HttpResponseMessage response = client.GetAsync(
                        "https://{account}.visualstudio.com/DefaultCollection/_apis/build/builds").Result)
            {
                response.EnsureSuccessStatusCode();
                string responseBody = await response.Content.ReadAsStringAsync();
                Console.WriteLine(responseBody);
            }
        }
    }
    catch (Exception ex)
    {
        Console.WriteLine(ex.ToString());
    }
}

I’ll give you a better example using OAuth to support integrated auth (rather then embedding credentials) as soon as I get the chance.

If you want a “real” example, check out the source to our ZenDesk plugin on CodePlex: http://vsozendesk.codeplex.com

Using Zapier to connect services

I also encourage you to check out Zapier.  There are a number of similar services but I like this one.  It makes it really easy to wire up Service hook event producers to consumers.  It provides a very nice wizard that walks you through the process.  You can visit the Visual Studio Online Zapier page here: https://zapier.com/zapbook/visual-studio-online/ to learn more about hooking VS Online up and see the hundreds of service connections they enable.

Here’s some screen captures from the wizard to connect Visual Studio Online to Asana to show how easy it is.

image

image

image

 

Overall I’m really excited about this new work.  We’ve been working hard on it for months and I encourage you to check it out.  It’s not nearly done.  The REST APIs will evolve.  The docs need work.  We need more samples.  Etc.  But it’s a very good start (IMHO) and I think you’ll like it.  Every sprint we’ll be producing updates to make it better.  Check it out and let us know what you think.

Brian

0 comments

Discussion is closed.

Feedback usabilla icon