逻辑应用程序中的图形分页

2024-05-02

我尝试通过 HTTP 连接器、注册的应用程序和 Microsoft Graph 获取特定组中的所有用户。

注册的应用程序具有 Directory.Read.All 权限。

我的想法是我打电话给nextLink只要它存在,同时附加所有获取的用户的userPrincipalName到一个数组,最终用该组的所有用户填充该数组。

我的逻辑应用程序如下所示:

不幸的是,我只差 1 点声誉来发布图片,请原谅。这 3 个链接应该提供我的应用程序结构的概述。

First, nextLink被初始化为第一个 Graph API 端点。该变量设置为当前nextLink通过until 循环的每次迭代。

其次,出于本练习的目的,我只获取前 5 个用户。我知道只有 9 个用户:

最后,我对之前初始化的“users”数组和 HTTP get 方法中的“value”数组调用 union 方法,以获取包含所有用户的单个数组:


问题在于 HTTP 操作始终返回相同的前 5 个用户。我已经检查过nextLink在对 Graph 的第一个 HTTP GET 调用中提供的信息是正确的,方法是从运行历史记录中复制它并将其粘贴到 Microsoft Graph Explorer 中,然后正确返回接下来的 4 个用户。

我还确保,对于直到循环中的每次迭代,我都使用以下命令调用 Graph APInextLink正如预期的那样来自上一次迭代。

The nextLink当我在图形资源管理器中测试它时,逻辑应用程序内部返回的结果完全相同,但相同nextLink从 Graph Explorer 和我的逻辑应用程序内部调用时,返回 2 个不同的结果。

为什么结果总是与预期的前 5 位用户相同,而不是接下来的 4 位用户?


如果不确定您会遇到此问题的原因,但根据您的要求,我做了以下示例:

{
    "definition": {
        "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
        "actions": {
            "Initialize_variable": {
                "inputs": {
                    "variables": [
                        {
                            "name": "GetGroupUrl",
                            "type": "string",
                            "value": "https://graph.microsoft.com/v1.0/groups/<your group id>/members?$select=userPrincipalName&$top=5"
                        }
                    ]
                },
                "runAfter": {},
                "type": "InitializeVariable"
            },
            "Initialize_variable_2": {
                "inputs": {
                    "variables": [
                        {
                            "name": "users",
                            "type": "array"
                        }
                    ]
                },
                "runAfter": {
                    "Initialize_variable": [
                        "Succeeded"
                    ]
                },
                "type": "InitializeVariable"
            },
            "Until": {
                "actions": {
                    "Compose": {
                        "inputs": "@union(variables('users'),body('HTTP')['value'])",
                        "runAfter": {
                            "HTTP": [
                                "Succeeded"
                            ]
                        },
                        "type": "Compose"
                    },
                    "HTTP": {
                        "inputs": {
                            "authentication": {
                                "audience": "https://graph.microsoft.com",
                                "clientId": "<app id>",
                                "secret": "<app secret>",
                                "tenant": "<your secret>",
                                "type": "ActiveDirectoryOAuth"
                            },
                            "method": "GET",
                            "uri": "@variables('GetGroupUrl')"
                        },
                        "runAfter": {},
                        "type": "Http"
                    },
                    "Set_variable": {
                        "inputs": {
                            "name": "GetGroupUrl",
                            "value": "@{if(equals(body('HTTP')?['@odata.nextLink'], null),null,body('HTTP')['@odata.nextLink'])}"
                        },
                        "runAfter": {
                            "Compose": [
                                "Succeeded"
                            ]
                        },
                        "type": "SetVariable"
                    }
                },
                "expression": "@equals(variables('GetGroupUrl'), '')",
                "limit": {
                    "count": 60,
                    "timeout": "PT1H"
                },
                "runAfter": {
                    "Initialize_variable_2": [
                        "Succeeded"
                    ]
                },
                "type": "Until"
            }
        },
        "contentVersion": "1.0.0.0",
        "outputs": {},
        "parameters": {
            "$connections": {
                "defaultValue": {},
                "type": "Object"
            }
        },
        "triggers": {
            "manual": {
                "inputs": {
                    "method": "GET",
                    "schema": {
                        "properties": {
                            "text": {
                                "type": "string"
                            }
                        },
                        "type": "object"
                    }
                },
                "kind": "Http",
                "type": "Request"
            }
        }
    },
    "parameters": {}
}

You can just replace the params with your own and paste it into your logic app code view and test it . It works for me, as you can see , each request results are different : enter image description here enter image description here

希望能帮助到你 。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

逻辑应用程序中的图形分页 的相关文章

随机推荐