【发布时间】:2020-07-12 19:54:09
【问题描述】:
我有一个 Azure 函数,它根据查询变量创建一个新的 Teams 团队。当我从命令行 curl 或 Invoke-RestMethod 函数时,它会执行并创建团队。当我从 Power Automate 流运行该函数时,该函数失败。
从 Flow 运行时,我收到的错误消息表明,对 MS Graph Teams 测试版 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'
任何关于在哪里寻找解决方案的指针将不胜感激。
【问题讨论】:
-
您的函数应用中有任何日志吗?当前的错误在这里不是很有帮助。
-
嗨,杰克。不幸的是,这是唯一真正的错误。但是,当我今天尝试重新生成错误时,错误消失了。没有更改任何代码,但由于 CRM 放置,整个应用程序已重新部署到不同的区域。
标签: azure powershell azure-functions microsoft-graph-api power-automate