Monday, April 11, 2016

Developing with Azure Resource Manager - Part 5 - Tip: Get all available api-version alternatives for the ARM endpoints

Introduction

Developing with Azure Resource Manager - Part 5 - Tip: Get all available api-version alternatives for the ARM endpoints

I've worked with the Azure Resource Manager API's extensively over the last 6 months. While doing so I've realized that the API versions changes and there's new functionality available. In order to know what versions are out there (and to be sure that's the full truth, given the documentation on MSDN is suffering from a severe lag in updates...), there's a few tricks I'm doing to list all available versions of a provider in the ARM REST API endpoints.

Please note. This post assumes you've already got your ARM AAD apps set up and you're authenticated to use the API. If you want to see how to do that, check out the other posts in this series.

Get available Azure Resource Manager API Versions with REST

If you've already got nice routines for getting your data through REST, then there's a nice way to get the API versions available by simply listing all the providers. This is pretty straight forward:

http://ift.tt/1S1peql}  

For example, a real query would look like this:

http://ift.tt/1N4K5fp  

This would yield an output similar to this:

"id":"/subscriptions/SUBSCRIPTIONGUID/providers/Microsoft.Storage",
   "namespace":"Microsoft.Storage",
   "resourceTypes":[
      {
         <snipped...>
         "apiVersions":[
            "2016-01-01",
            "2015-06-15",
            "2015-05-01-preview"
         ]
      }
      <snipped...>
   ],
<snipped...>  
}

That's an easy way to get all the available versions for various endpoints in the API. You could make it more granular or make it broader, should you want to. If you are unsure about what providers you can request, you could just run this query to list all providers:

http://ift.tt/1S1peqn  

Get available Azure Resource Manager API Versions with PowerShell

Personally I like PowerShell a lot, and I'm a bit more keen on just opening a new session and getting my info this way, if I don't have any reason to pull up a full new web based REST request. The PowerShell cmdlets for Azure Resource Manager have had a facelift lately, and things are starting to look the better. Also, running this through PowerShell is very straight forward, and will give you only the versions as opposed to the full REST query I showed previously where you'd get all kinds of other data too (because I didn't have any filters on that).

Login with your Azure RM Account

Login-AzureRmAccount  

It should get you logged in:
Developing with Azure Resource Manager - Part 5 - Tip: Get all available api-version alternatives for the ARM endpoints

Now, we can run any type of PowerShell we want, and to get the versions for (in my case) the Microsoft.Web provider, this is what it would look like:

((Get-AzureRmResourceProvider -ProviderNamespace Microsoft.Web).ResourceTypes | Where-Object ResourceTypeName -eq sites).ApiVersions

It should yield a result that looks something like this:

Developing with Azure Resource Manager - Part 5 - Tip: Get all available api-version alternatives for the ARM endpoints

Enjoy.


by Tobias Zimmergren via Zimmergren's thoughts on tech

No comments:

Post a Comment