Microsoft's Azure API Management allows developers to "publish APIs to external, partner, and employee developers securely and at scale." To manage these APIs, you could watch the tutorials on navigating the console and learning where things are, or you could use the command line. As with nearly every Azure service, Microsoft provides an API for API Management, and the Azure Resource Manager (AzureRM) PowerShell commands rely on this API.

Adam Bertram

Adam is a Microsoft Cloud and Datacenter Management Most Valuable Profressional (MVP) who specializes in Windows PowerShell. You can reach Adam at adamtheautomator.com or on Twitter at @adbertram.

Getting started ^

Before we can do anything with Azure in PowerShell, we need to get the Azure PowerShell module. Be sure to download the latest one from the PowerShell Gallery before getting started using Install-Module -Name AzureRm; I will be using v3.6.0.

Once we've got the module downloaded and installed, we'll then have to authenticate to our subscription. We'll do this by running Add-AzureRmAccount and providing the subscription credentials. However, if you're using a certificate or a service principal name (SPN) to authenticate, those methods work just fine as well.

I'm going to assume that you already have an API Management instance setup to hold your APIs. If not, Microsoft provides a tutorial on how to set one up. You will also need to have an Azure app service created as a destination to send the API requests to.

Discovering the API Cmdlets ^

Now that we're authenticated to Azure and are ready to go, let's see what kind of cmdlets we have available for working with Azure API Management. To figure out what cmdlets we have, I'll use the Get-Command cmdlet to see the modules installed along with the AzureRm module.

I know from experience there are lots of dependent modules that come along. Chances are, the commands for managing API Management APIs are in one of those modules. By running Get-Module -Name *API* -ListAvailable, I can see that I now have a module called AzureRM.APIManagement. I'll now use Get-Command again and see all the cmdlets in there.

AzureRm cmdlets

AzureRm cmdlets

I can see right away there are lots of commands that aren't necessarily tied to managing the APIs like we're interested in. Let's scope that down a bit by running Get-Command -Module AzureRM.ApiManagement -Name *AzureRmApiManagementApi* to get only the cmdlets that work with the APIs.

Creating an Azure API Management API ^

Let's first see what it takes to build one of these APIs. One of the first things you might find odd is the use of the Azure context. You need a context to work with any of the Azure API management commands. Create a context with New-AzureRmApiManagementContext. This object represents the API Management Service you've already created.

After saving the context, you'll use this in every one of your calls to Azure. Now we need to run New-AzureRmApiManagementApi to create the API. Since this command requires a few parameters, I'll save some space by using parameter splatting.

If all goes well, the command will return an object representing your newly created API.

Created API

Created API

We can now see the API by running Get-AzureRmApiManagementApi -Context $azrContext. This should return the same object returned during creation.

Modifying existing APIs ^

Now that I have created an API, I see I forgot to add a description. I can change existing APIs with the Set-AzureRmApiManagementApi cmdlet. Using Set-AzureRmApiManagementApi requires knowing a few attributes of the API I wish to modify. To change only the attribute we're looking for (Description), I'll capture the existing API and use those attributes with Set-AzureRmApiManagementApi.

The requirement to provide the other properties is a noticeably convoluted way to make changes. But unless Microsoft changes this cmdlet behavior, we can't do much about it.

Removing existing APIs ^

Now that we've created an API and have modified it, we'll now remove it. Since we've already got our API saved to the $api variable, we can reference its ApiId property to pass it then to Remove-AzureRmManagementApi. This removes the API just as quickly as we created it.

Win the monthly 4sysops member prize for IT pros

Share
0

Related Posts

0 Comments

Leave a reply

Your email address will not be published. Required fields are marked *

*

CONTACT US

Please ask IT administration questions in the forum. Any other messages are welcome.

Sending
© 4sysops 2006 - 2017

Log in with your credentials

or    

Forgot your details?

Create Account