azure api management,

Azure API Management with REST

Sven Malvik Sven Malvik Connect Mar 14, 2020 · 3 mins read
Azure API Management with REST

Today, we will provision Azure API Management by using Postman as an API client, sending plain web requests to Azure. We already provisioned an APIM instance in the last post from within the Azure Portal. This is the fastest way of getting an instance up and running to try out APIM. But if you want to put an instance into production, we should be able to automate this process. Provisioning with REST can be one step in that direction.

Create a Service Principal with the Azure CLI

Whenever we send a request to Azure, we need to set an Authorization token in the header. We get this token by creating a Service Principal.

Let’s first login. We use the Azure CLI for that.

The Json response gives us two information that we need. Id which is our subscriptionId and the tenantId.

The Json response gives us two information that we need. Id which is our subscriptionId and the tenantId.

az loginaz login

Then, we create the service principal and give it a name.

Create service principalCreate service principal

We got now also the password of the service principal that we’ll need for retrieving the access token.

2 Different Ways of Retrieving an Access Token

We will need Postman, so great if you can download and install Postman first. Otherwise, cURL works just fine of course. It’s just less work because I will share a pre-made collection of requests with you.

When you have installed Postman, you can simply load a collection of requests into Postman. You should now see this in Postman.

Postman CollectionPostman Collection

Click on the Settings icon of the “Azure REST”-collection in the top-right corner for setting the parameters like TenantId, ClientId (AppId), ClientSecret (Password) and SubscriptionId.

Postman Environment VariablesPostman Environment Variables

We can now send the first request for retrieving an access token.

Azure Access Token in PostmanAzure Access Token in Postman

There we are. Actually, there is a simpler way of retrieving an access token through the Azure CLI directly. This works fine in case you just want to try out some API endpoints.

az account get-access-tokenaz account get-access-token

It’s now time to create an instance of API Management.

Create an instance of API Management with Postman

Create a new request inside the Azure REST collection in Postman by copying the example request from the API Management documentation. Create a PUT request with the following url. Remember to replace the values.

Then, add an Authorization header with the following bearer token Bearer

The bearer token gets picked up by Postman when we retrieve the access token. Take a look at the “Test” pane of this request. You could also paste in the access token directly of course.

Last, put this json payload inside the body:

  "properties": {
    "publisherEmail": "YOUR_EMAIL",
    "publisherName": "YOUR_NAME"
  "sku": {
    "name": "Consumption",
    "capacity": 0
  "location": "West Europe",
  "tags": {
    "Owner": "YOUR_NAME"

Let’s now send the request.

Postman send requestPostman send request

That was a success and we can see the result in the portal.

Created Azure API Management instance from PostmanCreated Azure API Management instance from Postman


Provisioning an instance of API Management with REST is a pretty straightforward process. The only complicated task was to create a service principal (spn). This spn is not configured yet, and we should do this, but it’s content for another post.

Join Newsletter
Get the latest updates right in your inbox. I never spam!
Sven Malvik
Written by Sven Malvik