Exploring Azure Management APIs with az rest and az resource

Share
Exploring Azure Management APIs with az rest and az resource
Photo by ThisisEngineering / Unsplash

For years, the resources.azure.com website provided a convenient way to explore and interact with Azure resources through raw HTTP calls to the Azure Management APIs. It was particularly useful for performing custom REST operations directly against Azure resources. Sadly, this tool has been retired, leaving many of us searching for alternatives.

Microsoft has introduced a new Resource Explorer view in the Azure Portal. While this new view allows for some exploration, it lacks the robust "raw" HTTP interaction capabilities of its predecessor I loved so much.

In this article, I’ll share how you can use Azure CLI commands—az rest and az resource—to replicate the functionality of resources.azure.com and perform raw REST API calls to the Azure Management APIs.


The New Resource Explorer in Azure Portal

The Azure Portal now includes a Resource Explorer view that allows you to navigate the Azure resource hierarchy. While it’s a step forward, it doesn’t fully replicate the simplicity of performing raw REST API calls directly from the browser.

You can access the Resource Explorer here:
Resource Explorer React View


Using az rest for Raw REST API Calls

The az rest command is a versatile Azure CLI tool that allows you to perform raw REST API operations. It supports all HTTP verbs (GET, POST, PUT, DELETE, etc.) and lets you specify headers, query parameters, and request payloads.

Performing a Simple GET Request

If you want to perform a GET request on a specific resource, you can use az rest. For example, below is how you retrieve a managed certificate resource:

az rest --method GET --url '/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test/providers/Microsoft.App/managedEnvironments/test-cae/managedCertificates/mydomain.com-cert?api-version=2026-01-01'

Key Points:

  • --method: Specifies the HTTP verb (GET in this case).
  • --url: The full REST API endpoint for the resource, including the subscription ID, resource group, provider namespace, resource type, resource name, and API version.

Simplifying GET Requests with az resource

For simple GET operations, you can also use az resource show. This command is specifically designed for retrieving resource details and requires only the resource ID.

az resource show --ids '/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test/providers/Microsoft.App/managedEnvironments/test-cae/managedCertificates/mydomain.com-cert'

Why Use az resource?

  • Ease of Use: No need to specify the HTTP verb or API version; az resource automatically handles it for you.
  • Resource-centric: Ideal for users who want to query resource specifics without dealing with REST API intricacies.

Performing Other HTTP Verbs with az rest

For operations like PUT, POST, or DELETE, az rest provides flexibility to send custom payloads directly in the command or from a file.

Example: Creating a Public IP Address

Using a JSON file (body.json) to specify the request payload:

az rest --method PUT --url https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/publicIPAddresses/{publicIpAddressName}?api-version=2019-09-01 --body @body.json

Alternatively, you can specify the payload directly in the command:

az rest --method PUT --url https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/publicIPAddresses/{publicIpAddressName}?api-version=2019-09-01 --body '{"yourjson": "object"}'

Key Points:

  • --method: Specifies the HTTP verb (PUT in this case).
  • --body: The request payload, either as a JSON file (@body.json) or inline JSON.

Common Use Cases for az rest

Here are a few scenarios where az rest shines:

  1. Testing Azure Management API Calls: Ideal for developers building applications that integrate with Azure APIs.
  2. Custom Operations: Perform actions not directly supported by your tool of choice.
  3. Automation: Use az rest in scripts to automate custom operations on Azure resources.

Comparing az rest and az resource

Feature az rest az resource
HTTP Verbs Supports all verbs (GET, POST, PUT, DELETE) Easier for GET operations
Payload Support Allows sending JSON payloads Not applicable
API Version Requires manual specification Automatically inferred
Ease of Use Flexible but requires detailed inputs Simplified for basic queries

Summary

While resources.azure.com is no longer available, Azure CLI provides excellent alternatives in az rest and az resource. These tools enable raw interaction with Azure Management APIs, empowering you to perform custom operations directly from your terminal.

When to Use az rest

  • For complex operations requiring HTTP verbs other than GET.
  • When sending custom payloads as part of the request.

When to Use az resource

  • For simple GET operations to retrieve resource details.

References

  1. Azure CLI Reference - az rest
  2. Azure CLI Reference - az resource
  3. Azure REST API Reference

Happy REST API testing and resource exploration! Let me know if you need further articles with Azure CLI or REST API integrations.

Read more