You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

调用Azure REST API时如何使用分页?Logic Apps获取VM列表遇分页问题

How to Handle Azure VM List Pagination in Logic Apps

Hey there! I’ve tackled this exact scenario before, so let me walk you through how to get all your VM results using that nextLink you’re seeing, and clear up the HTTP header question upfront.

First: No, You Can’t Use HTTP Headers for This Pagination

Azure’s Compute API (for listing VMs) doesn’t support pagination via HTTP headers like Range or Page. Instead, it uses a nextLink-based pagination pattern—this is the standard approach for many Azure REST APIs.

Step-by-Step to Fetch All VM Results in Logic Apps

Here’s how to build this out in your Logic App:

  1. Initial API Call to Get First 50 VMs

    • Add an HTTP action to your Logic App. Use the GET method and set the URL to:
      https://management.azure.com/subscriptions/{your-subscription-id}/providers/Microsoft.Compute/virtualMachines?api-version=2023-07-01
      
    • Authenticate with Azure AD (use the "Managed Identity" option if your Logic App has one, or a service principal).
    • After running this action, you’ll get a response with:
      • value: An array of the first 50 VMs
      • nextLink: The URL to fetch the next page of results (if there are more than 50)
  2. Parse the Response (Optional but Recommended)

    • Add a Parse JSON action right after the HTTP call. Use the schema from the VirtualMachineListResult definition (you can generate it automatically by pasting a sample response from your first API call). This makes it way easier to access value and nextLink later.
  3. Set Up a Loop to Fetch Remaining Pages

    • First, initialize an array variable (e.g., allVMs) to store all your VM results. Append the initial value array to this variable.
    • Add a Do Until loop action. Set the loop condition to:
      @equals(variables('nextLink'), null)
      
      (Or check if it’s an empty string, depending on how the API returns it when there are no more pages.)
    • Inside the loop:
      • Add another HTTP action, and set the URL directly to the nextLink variable from your previous response. Use the same authentication as the first call.
      • Parse this new response with another Parse JSON action (reuse the same schema).
      • Append the new value array to your allVMs variable.
      • Update the nextLink variable to the new nextLink value from this response.
    • The loop will keep running until nextLink is null, meaning you’ve fetched all pages of results.

Key Notes to Avoid Headaches

  • Permissions: Make sure your Logic App’s identity has the right Azure RBAC permissions (like Virtual Machine Contributor or Reader) to list VMs across your subscription.
  • Rate Limits: Azure has API rate limits—if you have hundreds/thousands of VMs, add a small delay (e.g., 1-2 seconds) inside the loop to avoid getting throttled.
  • API Version: Always use the latest stable API version to ensure you’re getting the most reliable pagination behavior.

内容的提问来源于stack exchange,提问作者Beefcake

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 07:07:49