触发 Azure Function 从 Power Automate 创建 MS Graph Teams beta

Trigger Azure Function creating MS Graph Teams beta from Power Automate

我有一个 Azure Function,它根据查询变量创建一个新的 Teams 团队。当我从命令行卷曲或调用 RestMethod 函数时,它会执行并创建团队。当我 运行 来自 Power Automate 流程的功能时,该功能失败。

当 运行ning 来自 Flow 时,我收到的错误消息表明,对 MS Graph Teams beta API 的调用导致了这个问题:

Microsoft.Azure.WebJobs.Host.FunctionInvocationException: Exception while executing function: Functions.NewTeam
 ---> Microsoft.Azure.WebJobs.Script.Workers.Rpc.RpcException: Result: Failure
Exception: System.Management.Automation.CmdletInvocationException: {
  "error": {
    "code": "NotFound",
    "message": "Failed to execute Templates backend request CreateTeamFromTemplateRequest. Request Url: https://teams.microsoft.com/fabric/templates/api/team, Request Method: POST, Response Status Code: NotFound, Response Headers: Strict-Transport-Security: max-age=2592000\r\nx-operationid: 14c6acc3601661469f152ac3d1d46b8a\r\nx-telemetryid: |14c6acc3601661469f152ac3d1d46b8a.7a1c5868_1.\r\nX-MSEdge-Ref: Ref A: 6259AF5FA1174BBCA9C2A70A448D15F4 Ref B: DB3EDGE1222 Ref C: 2020-04-01T05:38:26Z\r\nDate: Wed, 01 Apr 2020 05:38:26 GMT\r\n, ErrorMessage : {\"errors\":[{\"message\":\"Failed to execute request for MiddleTier CreateTeamS2SAsync. Status code: NotFound.\"}],\"operationId\":\"14c6acc3601661469f152ac3d1d46b8a\"}",
    "innerError": {
      "request-id": "37cb7b1c-ae0f-4191-8878-5a6d91578dd8",
      "date": "2020-04-01T05:38:26"
    }
  }
}

我必须在团队创建调用之前生成一个令牌并且执行得很好。

我已修复 CORS 以允许调用跨域。来自 FLOW 的其他调用按预期工作。只有此代码中的最后一行失败并且仅当从 Flow 调用时:

            $params = @{
                Header        = Get-AzureMSGraphHeader @credential #calls the Graph endpoint and generates a token
                Method        = 'Post'
                Uri           = 'https://graph.microsoft.com/beta/teams'
            }
            $params.Body = @{
                displayName           = $TeamName
                description           = $TeamName
                "template@odata.bind" = "https://graph.microsoft.com/beta/teamsTemplates('standard')"
                'owners@odata.bind'   = $Owners
                visibility            = 'Private'
            } | convertto-json
            Write-Information "Executing command"
            Invoke-AzureMSGraph @params #calls the graph endpoint with the body and header above

Invoke-AzureMSGraph 是 Invoke-RestMethod 的包装器。它将 ContentType 设置为 'application/json'

如果能提供有关在哪里寻找解决方案的任何指示,我们将不胜感激。

在新创建的 Azure 函数(在不同区域)上部署完全相同的代码时,问题消失了。所有代码都是一样的。

在这种情况下,可部署的模板就派上用场了。