Uncategorized

Part 1: ANF API 101 with Postman

Azure NetApp Files is a first party Azure service and is therefor fully integrated with Azure Resource Manager, the Azure Portal, CLI, PowerShell and REST APIs.

REST APIs can be a bit scary if you’ve never worked with them before. A really good ANF API resource is the official Microsoft Docs page. It lists all the available operations and parameters and it even lets you execute API calls from within your browser!

One of the tools that helped me out a lot when I started learning APIs is Postman. In this first part we’ll look at configuring Postman for Azure and how to setup authentication.


Step 1: create service principal for authentication
Open the Azure Cloud Shell and enter the following command.
az ad sp create-for-rbac --name ServicePrincipalPostman

Save the output and keep it in a safe place. Note the service principal is a Contributor (default) at this point. If you would like to change the role to something more ANF specific, you can use this previous blog post as guidance.


Step 2: install Postman
Download and install the Postman application.
https://www.postman.com/downloads/

Postman consists of 2 important parts, collections and environments. The collection is basically a folder that lets you organize specific API calls. To make life easier we’ve already created an Azure NetApp Files collection that contains some basic operations!


Step 3: download and import Postman collection

Download and extract ANF_Postman_v1.0.zip. Open Postman and from the top left menu select File –> Import… , upload ANF.postman_collection.json and click Import. The collection now appears on the left hand side.


Step 4: import Postman environment
Next we’ll import the Postman environment. The environment is a set of variables that are referenced by the API calls. Select File –> Import… , upload ANF.postman_environment.json and click Import.

Click on the top right Manage Environments button and select the newly created Azure NetApp Files environment.

As you can see, the variables for resource and api-version have already been filled out.


Step 5: insert missing variables
We’ll now proceed to insert the missing variables. Here’s an overview of what values need to be inserted.

VariableValue Description
tenanttenant value from the step 1 output
appIdappId value from the step 1 output
passwordpassword value from the step 1 output
subscriptionIdAzure Subscription ID
resourcehttps://management.azure.com/
resourceGroupNameResource group that contains the ANF account
api-version2020-07-01
accountNameANF account name
poolNameANF capacity pool name
volumeNameANF volume name
snapshotNameANF volume snapshot name

Your complete environment should look something like this:


Step 6: request and store authentication token
We’re now ready to fire off our first API call! Select the Request and Store Token (Run Me First) entry from the collection on the left.

Let’s have a look at what this specific call does. Select the Body tab . Here you can see the data that will be passed in the HTTP body. The call will pass the variables for {{appId}} and {{password}} that we’ve configure in the previous step. Click on Send.

If the request was successful, it will generate a 200 OK status code and an access_token is returned.

This token is valid for 1 hour and is automatically stored in Postman as a global variable. This is done by a Javascript that you can find in the Tests tab.

Click on the Environment quick look button (eye icon top right) to make sure the token variable has been stored.

That’s it for part 1! Stay tuned for the next part in which we’ll dive into some of the GET and PUT calls.

Part 2: https://anfcommunity.com/2021/04/29/part-2-anf-api-101-with-postman/

2 comments

Leave a Reply

%d bloggers like this: