Calling Azure Resource Manager REST APIs

Often times, you may think, “hey mother of documentation for all things released on Azure is the REST API, and how do I access it?” Well, here is the solution.

Let’s first start with high level.

  1. Get a REST client. You can use Fiddler, or Postman (a Google Chrome extension).
  2. Make sure you have an Azure subscription co-administrator user on your Azure AD that has access to your subscription (no your Microsoft ID, Live ID, Passport, whatever is the latest name for that does not work, it has to be an Azure AD user)
  3. Get an OAUTH access token for that co-admin user
  4. Craft the REST request on your client

Get an OAUTH access token

Create an AD application for your client following the instructions here.

I use LINQPad for code snippets, following snippet uses Active Directory Authentication Library (ADAL) available through Nuget.

Copy the whole string starting with “Bearer …” from the result.

Crafting the REST request

Let’s take the example of listing the resource groups. Go to the related ARM documentation section.

Get your subscription ID from the portal

AzureSubscriptionSettings

Build the URI by copying from the documentation and plug in your Subscription ID

https://management.azure.com/subscriptions/{subscription-id}/resourcegroups?api-version={api-version}&$top={top}$skiptoken={skiptoken}&$filter={filter}

Use the API version provided at https://msdn.microsoft.com/en-us/library/azure/8d088ecc-26eb-42e9-8acc-fe929ed33563#bk_common

And follow the instructions for the headers on this page.

Then send the request. Voila! Here comes back your resource groups.

Postman