Getting started with Cloud-based Load Test REST APIs

REST API’s are pretty cool, enabling you to do things like write your own custom reports, write your own interfaces and of course integrating load tests into your build. 

Looking at the sample referenced with our REST API documentation; at 400 lines to demonstrate 4 API’s I must admit I found it pretty daunting so I thought I would see if I could simplify that somewhat.

Just like the documentation indicates: the first place you want to start is to enable alternate credentials.  This is done by opening your user profile from Visual Studio Online. 


And enabling alternative credentials.



At this point we are ready to start writing a sample!

Since the goal of this demo is to keep it simple I decided to use ASP.NET and let it handle all the Async goo. 



To do this all you need to do is set the property Async=”True” on the page(see below).  

While on the page I also tossed on a Textbox to display the result of the REST calls.


Here is the markup for that page:

<%@ Page Language="C#" AutoEventWireup="true" async="true" CodeBehind="simple.aspx.cs" Inherits="ssimple.simple" %>


<!DOCTYPE html>


<html xmlns="">

<head runat="server">




    <form id="form1" runat="server">


        <asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine"></asp:TextBox>






To make the code easier to read and access the functionality needed; bring in the following four namespaces and corresponding references:

using System.Globalization;

using System.Web.Configuration;

using System.Net.Http;

using System.Net.Http.Headers;

At this point I am ready to call my REST API: /TESTDROPS. 

An important note: You need to use the VSCLT URI for Cloud-based load test REST API’s So the entire URL would look like:


While the REST API only takes one line of code (HttpClient.GetStringAsync…); a couple of lines of code are required to setup up the connection.

Since we are letting ASP.NET handle the Async handling you need to set this property in the event handler.


protected async void Page_Load(object sender, EventArgs e)



            HttpClient client = new HttpClient();

            //setup the client connection

            var vsoAccountUsername = WebConfigurationManager.AppSettings["VSOnlineAccountUsername"];

            // var vsoAccountUsername = "";

            var vsoAccountPassword = WebConfigurationManager.AppSettings["VSOnlineAccountPassword"];

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",

            Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes(string.Format(CultureInfo.InvariantCulture, "{0}:{1}", vsoAccountUsername, vsoAccountPassword))));

            TextBox1.Text = await client.GetStringAsync("");



If you are getting an HTTP 401 error when running this sample more than likely your account doesn’t have a Visual Studio Ultimate Subscription associated with it or you haven’t enabled alternate credentials.

For those of you a little more old school here is a console application version: 


public static async void GetTestRuns()
                var elsAccountUrl = new Uri(ConfigurationManager.AppSettings["ElsOnlineAccountUrl"]);
                var vsoAccountUsername = ConfigurationManager.AppSettings["VSOnlineAccountUsername"];
                var vsoAccountPassword = ConfigurationManager.AppSettings["VSOnlineAccountPassword"];

                using (var client = new HttpClient())
                        new MediaTypeWithQualityHeaderValue("application/json"));

                    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",
                                string.Format("{0}:{1}", vsoAccountUsername, vsoAccountPassword))));

                    using (HttpResponseMessage response = client.GetAsync(elsAccountUrl+"/_apis/clt/testruns").Result)
                        string responseBody = await response.Content.ReadAsStringAsync();
            catch (Exception ex)




If you haven’t played with App.Config files, here is an example:

        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
        <!– The {account} needs to be replaced by your Visual Studio Online account name. –>
        <add key="ElsOnlineAccountUrl" value="
https://{account}" />

        <!– The {username} and {password} need to be replaced by the alternate credentials you have set in VSO against your identity. –>
        <add key="VSOnlineAccountUsername" value="{username}" />
        <add key="VSOnlineAccountPassword" value="{password}" />


To make it has easy as possible, I have also attached a zip file of the web project:


In case you are wondering what the return looks like I would recommend just running the URL: https://{youraccount}

Here is a screenshot of the web application as well





SEO Tagging: “worlds simplest REST API Sample”