This post will show you the fastest way to call the Azure REST APIs using Postman.
Let’s create a Postman Collection, add a pre-request script, and set some variables.
- In Postman, click the “New” button in the upper left and select “Collection”.
- Give it a name, but don’t click the “Create” button yet.
Postman allows you to assign a pre-request script to a collection, which is code that will run before every request. We’ll use that to generate a
bearerToken that is required in the
Authorization header of each Azure REST API request.
This script will do a POST to login.microsoftonline.com and put the response token in a global variable called
- Copy this code block into your collections pre-request script block.
Postman allows you to set variables at the collection level. We’ll put the variables required by the pre-request script and the Azure REST APIs in the “Variables” tab.
- Create the following variables. We’ll add the variable values in the next section, so keep this form open.
Make sure you add the variable values to the CURRENT VALUE column NOT the Initial Value column.
Keep the “Create Collection” dialog open and continue to the next step.
Open Azure Cloud Shell - https://shell.azure.com
Create a Service Principal
Run the following command to create a service principal - which is a non-user account that can be used to call the Azure REST APIs.
Make sure you change
sp1with a unique name.
az ad sp create-for-rbac -n "sp1"
- Copy the outputed variables to Postman Collection variables
- Get Subscription Id
Run the following command to get your subscription Id.
az account show --query id -otsv
- Copy the outputed Subscription Id to Postman Collection Variables tab
At this point your variables tab should look like this - with every variable filled out.
- Click the ‘Create’ Button on the Postman Collection form.
Paste the following URI into the Postman Request URI field
Authorizationheader and set value to
Save the Request to the Postman Collection you created earlier.
The Postman Collection pane should now look like this:
Click the ‘Send’ Button
Observe Request Output
You will see the REST request output in the bottom pane
And that is how to call the Azure REST APIs with Postman in no time flat!