Microsoft Azure provides a number of ways to interact with Azure resources
Learn how to get started with Azure APIs in Postman. If you are using Azure APIs for the first time, you can follow the steps in this guide to call the APIs using requests sent through the Postman client. You can use these requests to experiment with an API before you develop your application, or programmatically run a sequence of API calls to create and manage your infrastructure on Azure.
Microsoft.Authorization/roleAssignments/write
permissions to manage role assignmentsIn this section, let's use the Azure CLI to generate credentials, and explore how to authenticate with the Azure REST APIs.
az login
command. You will be redirected to log in to your Azure account in a web browser. Upon successful login, you will be presented with your account details, as shown below. Please take note of the id
variable, as we need this information later. The id
variable is our subscription ID on Azure. az account set
command. Use the -n
parameter to specify the subscription name, i.e: az account set -n "MSDN Platforms Subscription"
. A list of your subscriptions can be found in the Azure portal.az group create --location [Azure Location, i.e: westus] --resource-group [Resource Group]
az ad sp create-for-rbac -n [SP_Name] --role Owner --scope "/subscriptions/[Subscription_ID]/resourceGroups/[ Resource Group]"
. The output should look like this: This command will provide the credentials we need to work on Postman to test Azure APIs. Copy the credentials to somewhere safe. Please do not expose the credentials!--role
flag and specify the scope of the SP credentials with the --scope
flag. Documentations included here.Some built-in roles in Azure role-based access control (RBAC) include:az ad sp create-for-rbac -n Postman --role Owner --scope
{
"appId": "e8df7f8a-XXXX-XXXX-XXXX-XXXXXXXXXXX",
"displayName": "azure-cli-2023-XX-XX-XX-XX-XX",
"password": "XXXXX~XXXXXXXX.XXXXXXXXXXX",
"tenant": "XXXXXX-XXXXX-XXXX-XXXX-XXXXXXXXXXX"
}
az account show --query id -o tsv
or az account subscription list
. The output should look like the following:az account subscription list
The command requires the extension account. Do you want to install it now? The command will continue to run after the extension is installed. (Y/n): y
Run 'az config set extension.use_dynamic_install=yes_without_prompt' to allow installing extensions without prompt.
Command group 'account subscription' is experimental and under development. Reference and support levels: https://aka.ms/CLI_refstatus
[
{
"authorizationSource": "Legacy",
"displayName": "MSDN Platforms Subscription",
"id": "/subscriptions/[subscription ID]",
"state": "Enabled",
"subscriptionId": "[subscription ID]",
"subscriptionPolicies": {
"locationPlacementId": "Public_2014-XX-XX",
"quotaId": "MSDN_2014-XX-XX",
"spendingLimit": "On"
}
}
]
Postman variable | Azure data |
|
|
|
|
|
|
|
|
| [Resource Group] |
| [Subscription ID] |
| [leave it blank, we will programmatically fill the field next] |
pm.test("Check for collectionVariables", function () {
let vars = ['clientId', 'clientSecret', 'tenantId', 'subscriptionId'];
vars.forEach(function (item, index, array) {
console.log(item, index);
pm.expect(pm.collectionVariables.get(item), item + " variable not set").to.not.be.undefined;
pm.expect(pm.collectionVariables.get(item), item + " variable not set").to.not.be.empty;
});
if (!pm.collectionVariables.get("bearerToken") || Date.now() > new Date(pm.collectionVariables.get("bearerTokenExpiresOn") * 1000)) {
pm.sendRequest({
url: 'https://login.microsoftonline.com/' + pm.collectionVariables.get("tenantId") + '/oauth2/token',
method: 'POST',
header: 'Content-Type: application/x-www-form-urlencoded',
body: {
mode: 'urlencoded',
urlencoded: [
{ key: "grant_type", value: "client_credentials", disabled: false },
{ key: "client_id", value: pm.collectionVariables.get("clientId"), disabled: false },
{ key: "client_secret", value: pm.collectionVariables.get("clientSecret"), disabled: false },
{ key: "resource", value: pm.collectionVariables.get("resource") || "https://management.azure.com/", disabled: false }
]
}
}, function (err, res) {
if (err) {
console.log(err);
} else {
let resJson = res.json();
pm.collectionVariables.set("bearerTokenExpiresOn", resJson.expires_on);
pm.collectionVariables.set("bearerToken", resJson.access_token);
}
});
}
});
bearerToken
. This happened when the pre-request script executed. Bearer
in the required format to the request Authorization
header. Authorization
header with a value formatted like Bearer xxx
where xxx
is the saved token. Now that you have properly configured the authorization at the collection-level, you can re-use it throughout other requests within the collection, unless otherwise configured.
In the next sections, let's explore other Azure APIs.
In the previous section, you may have already made your first successful Azure REST API request. Let's review.
PUT
(instead of GET
). Also notice a path variable notated as :resourceGroup
in the request URl and editable under the Params tab next to resourceGroup
key. Feel free to update the value to your own resource group name. Under the Body tab, feel free to update the required location
. And then Send the API request. Check out other Azure REST APIs for the Resource Group.
For each Azure resource that you plan to work with, add the resource to your resource group.
Each of the following APIs will explore a specific Azure resource corresponding to the specific AI service as a prerequisite. However, if you will be using multiple AI services in the same project, you can create a Cognitive Services resource instead, which provides access to Vision, Language, Search, and Speech services using a single API.
Not all of the following services are available in every region. Please refer to Azure Products by Region to ensure that you pick a correct region when creating your resource.
Azure Cognitive Search is a cloud search service that gives developers infrastructure, APIs, and tools for building a rich search experience over private, heterogeneous content in web, mobile, and enterprise applications.
api-key
with each individual request or at the folder-level so that requests within the folder inherit the authorization method. Select the "Cognitive Search" folder and configure the Authorization method to automatically add an api-key
header to each request within the folder. Remember to also save your API key as a collection variable. searchServiceName
and searchIndexName
to begin exploring the Azure Cognitive Search API.In Postman, explore other Azure AI services within the "AI" folder. Notice folder-level authorization methods. And expand the request documentation using the icon on the far right for more details and links to additional resources.
If your API request isn't behaving as expected, there can be many possible reasons. To find out what the problem is, you can use the Postman Console to troubleshoot your request.
Open the Console by selecting Console icon in the Postman footer. You can view network data, log statements, and the raw calls being sent through Postman.
Once you explore an API, you understand the basic building blocks of popular services on Azure. Next, organize your work into your own collections and workspaces in Postman.
Once you group API requests into collections, there are multiple ways to programmatically run those collections.
Once you have an API call working the way you want it to in Postman, generate client code to paste into your own applications.
For more hands-on tutorials, check out these resources.