Post

Azure - API

Azure - API

Introduction

  • This article outlines the steps to make an api call to Azure using the Thunder Client in VSCode.
  1. Get Azure Authentication Details

    • To authenticate, you’ll need an Azure Access Token. You can use the Azure CLI to obtain it.
    • Open a terminal and log in to Azure:
    1
    
     az login
    
    • Obtain an access token for the Azure REST API and copy the value of accessToken.
    1
    
     az account get-access-token --resource https://management.azure.com/
    
    • Example output:
    1
    2
    3
    4
    5
    6
    7
    
     {
     "accessToken": "eyJ0eXAiOiJKV1QiLCJhb...",
     "expiresOn": "2024-12-03T12:34:56.789Z",
     "subscription": "your-subscription-id",
     "tenant": "your-tenant-id",
     "tokenType": "Bearer"
     }
    
  2. Configure Thunder Client for Azure API Calls

    • Open Thunder Client in VS Code.
    • Create a new request by clicking New Request.
    • Set up the request:
    • Method: Select the HTTP method (e.g., GET, POST).
    • URL: Use the Azure Management API endpoint, such as: https://management.azure.com/subscriptions/{subscriptionId}/providers/Microsoft.Resources/subscriptions?api-version=2021-01-01
    • Replace {subscriptionId} with your Azure subscription ID.
    • Add authentication:
      • Go to the Auth tab in Thunder Client.
      • Select Bearer Token as the type.
      • Paste the accessToken you retrieved from the Azure CLI.
    • Set the Content-Type (if required):
    • Go to the Headers tab.
    • Add:

      1
      2
      
        Key: Content-Type
        Value: application/json
      
  3. Send the Request

  • Click Send to make the API call. Thunder Client will include your Bearer Token in the request headers for authentication.

Automate Token Generation

  • To avoid manually fetching tokens, you can automate it by:
  1. Using a script or task runner to fetch the token via az account get-access-token.
  2. Configuring Thunder Client’s Environment Variables to dynamically include the token.

Example script for a token fetch:

1
export AZURE_ACCESS_TOKEN=$(az account get-access-token --resource https://management.azure.com/ --query accessToken -o tsv)
  • Then use the token dynamically in Thunder Client by referring to it in your environment configuration.
This post is licensed under CC BY 4.0 by the author.