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.

https://management.azure.com/subscriptions/YOUR_SUBSCRIPTIONID/resourceGroups/YOUR_RESOURCEGROUP/providers/Microsoft.ApiManagement/service/YOUR_APIM_INSTANCE_NAME?api-version=2019-01-01

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

Conclusion

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

Latest Stories

Event-Driven Infrastructure with App Configuration

Azure App Configuration is great for externalizing application configurations. But what if an application is our infrastructure? How coul...

Sep 12, 2020

Logging in Azure API Management

This post is a complete step-by-step guide on how to send logs from Azure API Management to Azure Event Hub with PowerShell. We start by ...

Apr 11, 2020

Azure App Configuration Introduction

We build this great application that we configure exactly the way it fits into our environments, and then we realize that changing a conf...

May 09, 2020

Understanding Policies in Azure API Management

Policies are the heart of Azure API Management. They let us change the behavior of our APIs in a very flexible manner. Before I dive in t...

Apr 18, 2020

How To Debug Policies in Azure API Management. A Step-by-Step Guide.

In this post I want to briefly go through the Azure API Management extension for VSCode and how we can debug policies. It’s one of the qu...

Jan 16, 2021

How to Reference Key Vault Secrets in Azure API Management

In an enterprise, an Azure API Management instance is often shared by many teams and many developers. The developers may all have access ...

Feb 05, 2021

Introduction to Azure API Management

Azure API Management (APIM) is a way to create consistent and modern API gateways for existing backend services. It provides an interface...

Jan 25, 2021

How to Secure Azure Functions App with Azure API Management

How to use an Azure Managed Identity to authenticate against an Azure Functions app that is exposed through Azure API Management. Our Fun...

Feb 02, 2021

How To Manage Azure Virtual Machines

I will go through the first steps for managing Virtual Machines. We will create a Windows VM, start the Internet Information Service IIS,...

Dec 26, 2020

Serving Website Images from Azure CDN with SSL

In this post I will show you step by step how to serve images on a website from Azure CDN with SSL enabled. My blog has a couple of Azure...

Apr 25, 2020

Using Azure API Management APIs with Docker

We use Azure API Management in some cases for calling external services from Azure Kubernetes Service (AKS). Azure API Management acts in...

Jun 27, 2020

Latest Stories

Event-Driven Infrastructure with App Configuration

Event-Driven Infrastructure with App Configuration

Azure App Configuration is great for externalizing application configurations. But what if an application is our infrastructure? How coul...

Sep 12, 2020

Logging in Azure API Management

Logging in Azure API Management

This post is a complete step-by-step guide on how to send logs from Azure API Management to Azure Event Hub with PowerShell. We start by ...

Apr 11, 2020

Azure App Configuration Introduction

Azure App Configuration Introduction

We build this great application that we configure exactly the way it fits into our environments, and then we realize that changing a conf...

May 09, 2020

Understanding Policies in Azure API Management

Understanding Policies in Azure API Management

Policies are the heart of Azure API Management. They let us change the behavior of our APIs in a very flexible manner. Before I dive in t...

Apr 18, 2020

How To Debug Policies in Azure API Management. A Step-by-Step Guide.

How To Debug Policies in Azure API Management. A Step-by-Step Guide.

In this post I want to briefly go through the Azure API Management extension for VSCode and how we can debug policies. It’s one of the qu...

Jan 16, 2021

How to Reference Key Vault Secrets in Azure API Management

How to Reference Key Vault Secrets in Azure API Management

In an enterprise, an Azure API Management instance is often shared by many teams and many developers. The developers may all have access ...

Feb 05, 2021

Introduction to Azure API Management

Introduction to Azure API Management

Azure API Management (APIM) is a way to create consistent and modern API gateways for existing backend services. It provides an interface...

Jan 25, 2021

How to Secure Azure Functions App with Azure API Management

How to Secure Azure Functions App with Azure API Management

How to use an Azure Managed Identity to authenticate against an Azure Functions app that is exposed through Azure API Management. Our Fun...

Feb 02, 2021

How To Manage Azure Virtual Machines

How To Manage Azure Virtual Machines

I will go through the first steps for managing Virtual Machines. We will create a Windows VM, start the Internet Information Service IIS,...

Dec 26, 2020

Serving Website Images from Azure CDN with SSL

Serving Website Images from Azure CDN with SSL

In this post I will show you step by step how to serve images on a website from Azure CDN with SSL enabled. My blog has a couple of Azure...

Apr 25, 2020

Using Azure API Management APIs with Docker

Using Azure API Management APIs with Docker

We use Azure API Management in some cases for calling external services from Azure Kubernetes Service (AKS). Azure API Management acts in...

Jun 27, 2020