APIs are available for most functionality and information in Azure. A token, which must be sent with the request, is usually required to retrieve the information.

Generating a token dynamically or retrieving it via a service principal is often a bit annoying. The az rest function can help here. It requests an authorization token from Azure Active Directory and then executes a request against the specified URL. The token just retrieved is set in the header.

However, not just any URL can be used. The function typically supports management APIs. The permitted URLs that can be used with az rest are provided by the respective cloud configurations. For the public Azure cloud they are:

PS /home/thomas_zuehlke> az cloud show --query endpoints

{
  "activeDirectory": "https://login.microsoftonline.com",
  "activeDirectoryDataLakeResourceId": "https://datalake.azure.net/",
  "activeDirectoryGraphResourceId": "https://graph.windows.net/",
  "activeDirectoryResourceId": "https://management.core.windows.net/",
  "appInsightsResourceId": "https://api.applicationinsights.io",
  "appInsightsTelemetryChannelResourceId": "https://dc.applicationinsights.azure.com/v2/track",
  "attestationResourceId": "https://attest.azure.net",
  "azmirrorStorageAccountResourceId": null,
  "batchResourceId": "https://batch.core.windows.net/",
  "gallery": "https://gallery.azure.com/",
  "logAnalyticsResourceId": "https://api.loganalytics.io",
  "management": "https://management.core.windows.net/",
  "mediaResourceId": "https://rest.media.azure.net",
  "microsoftGraphResourceId": "https://graph.microsoft.com/",
  "ossrdbmsResourceId": "https://ossrdbms-aad.database.windows.net",
  "portal": "https://portal.azure.com",
  "resourceManager": "https://management.azure.com/",
  "sqlManagement": "https://management.core.windows.net:8443/",
  "synapseAnalyticsResourceId": "https://dev.azuresynapse.net",
  "vmImageAliasDoc": "https://raw.githubusercontent.com/Azure/azure-rest-api-specs/main/arm-compute/quickstart-templates/aliases.json"
}

To retrieve information from the API, a call could look like this: az rest --url https://graph.microsoft.com/v1.0/me --query userPrincipalName

For example, to retrieve the pricing information for an Enterprise Agreement, the call can be made through the Azure Management API: az rest --url "https://management.azure.com/subscriptions/<SUBSCRIPTION-GUID>/providers/Microsoft.Billing/billingPeriods/202204/providers/Microsoft.Consumption/pricesheets/default?api-version=2021-10-01&$expand=meterDetails" --query properties.pricesheets[0]