How to list all available VM sizes in a region using .NET (ARM endpoint)

Today, I had a query from a developer asking how to silent authenticate and fetch the list of available VM’s sizes from a particular region using .NET code. They wanted to fetch this detail from their worker role more precisely. They wanted to call the URI as in this article silent authenticated

Method Request URI

On first sight, I thought this as an RDFE endpoint(older portal/SMAPI), but on closer look this turned to be an ARM end point.

How to identify the url is an RDFE/ARM endpoint?

Please note, for RDFE end point we may have to either use certificate based or native client way of authentication.

Since this is an ARM endpoint, we need to follow the service principal way to get the bearer token which is needed for the URI GET call’s.


Perform the following action one by one carefully as in this URL -

  1. Create an Active Directory application
  2. Get client id and authentication key
  3. Get tenant id
  4. Set delegated permissions
  5. Assign application to role


using System;
using System.IO;
using System.Net;
using Microsoft.IdentityModel.Clients.ActiveDirectory;

namespace ConsoleApplication1
class Program
static void Main(string[] args)

            var context = new AuthenticationContext(" "your_tenantid");
ClientCredential credential = new ClientCredential("your_client_ID", "your_client_secret");
AuthenticationResult result = context.AcquireToken("", credential);
var token = result.CreateAuthorizationHeader().Substring("Bearer ".Length);

            string uri = @"<your_subscription_Id>/providers/Microsoft.Compute/locations/Southeast Asia/vmSizes?api-version=2015-05-01-preview";
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri);
request.Headers.Add("Authorization:Bearer " + token);
var response = request.GetResponse().GetResponseStream();
var output = new StreamReader(response).ReadToEnd();


P.s:- I have used Adal to avoid async complexities.

on executing, image