How to call REST APIs on Azure Portal

Sometimes , we may facing this situation : we have a requirement and we can finish the process on portal manually . However , we can’t find the associated APIs to do it automatically by code.

So , this blog will provide a way to call all APIs you can fetch on Azure portal.

Prerequisites

  1. An active Azure subscription.
  2. An Azure subscription account.

Eamples

For instance, let’s say , I want to enable “application proxy” in AAD : 

As we all know ,there is no SDK, powershll or APIs published by Microsoft officially, we can do this function on Azure portal manually but unable to do it using code.

For this situation , we can try to fetch its request to have a try.

First , let’s try to fetch its whole request :

We can get all infos about this request so that we can call this API via code. The only problem  we should solve is getting the proper access token.

To get an access token, we should know what resource we need. So we should analyze the access token in the request we just captured :

So the resource we need should be : 74658136-14ec-4630-ad9b-26e160ff0fc6

So we should request access token in this way :
Request URL:

post https://login.microsoftonline.com/<your tenant ID>/oauth2/token

Request Header:

Content-Type: application/x-www-form-urlencoded 

Request Body:

resource=74658136-14ec-4630-ad9b-26e160ff0fc6&client_id=1950a258-227b-4e31-a9cf-717495945fc2&grant_type=password&username=<Azure admin username(URL encoded)>&password=<admin password(URL encoded)>

With this request, we are able to get an access token to call the API we want:

Ok ,let’s try to call this API with this access token :

Call this API successfully and  the function has been enabled :

Summary

This is a sample demo about how to fetch APIs you need on Azure portal . It will be helpful for your development. Feel free to contact us via aka.ms/devchat if you have any questions.

Leave a Reply

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