使用 REST API 更新逻辑应用连接上的 json 视图时不允许使用方法

问题描述 投票:0回答:1

我想使用 REST API 来更新 json 视图,就像我在这篇文章中问的那样:

由于json视图中的内容很多并且是动态的,所以我想在修改之前使用Get来获取内容,然后简单地用这个body更新修改Json视图以覆盖原始的json视图。

现在,我可以使用开发工具

F12
来获取以下URL的内容:

https://management.azure.com/subscriptions/<subscriptions>/resourceGroups/<resourceGroups>/providers/Microsoft.Web/sites/<LogicAppName>/workflowsconfiguration/connections?api-version=2018-11-01

然后我就可以获取Json View的内容了。

但是,我使用相同的URLPost/Put方法,例如:

$token = $(Token)
$headers = @{
  "Authorization" = ('Bearer {0}' -f $token)
  "If-Match"      = '*' 
  }
$url = "https://management.azure.com/subscriptions/<subscriptions>/resourceGroups/<resourceGroups>/providers/Microsoft.Web/sites/<LogicAppName>/workflowsconfiguration/connections?api-version=2018-11-01"
Invoke-RestMethod -Uri $url -Method Post -Body $JsonView -ContentType "application/json" -Headers $headers

结果是:

远程服务器返回错误:(405) 方法不允许。

即使我使用另一个网址:

https://management.azure.com/subscriptions/<SubscriptionId>/resourceGroups/<ResourceGroups>/providers/Microsoft.Web/sites/<LogicAppName>/deployWorkflowArtifacts?api-version=2018-11-01

还是同样的错误。

所以,我的问题是修改 json 视图的正确 REST API URL 是什么?

json powershell azure-logic-apps azure-rest-api
1个回答
0
投票

我确实同意 @10p 的观点,即 cli 命令是正确的,但要使用 PowerShell 获取内容,请使用以下脚本:

$token = (Get-AzAccessToken -ResourceUrl 'https://management.azure.com/').Token
$headers = @{Authorization="Bearer $token"}
$x=Invoke-WebRequest -Method GET -Headers $headers -Uri 'https://rith12.scm.azurewebsites.net/api/vfs/site/wwwroot/connections.json'
$x.Content

Output:

enter image description here

In Logic App(Before Updating):

enter image description here

To Update the Json view use below Scripts:

$token = (Get-AzAccessToken -ResourceUrl 'https://management.azure.com/').Token
$headers = @{
Authorization="Bearer $token"
  "If-Match"      = '*' 
}
$x=Invoke-WebRequest -Method GET -Headers $headers -Uri 'https://rith12.scm.azurewebsites.net/api/vfs/site/wwwroot/connections.json'
$testobj = $x.Content | ConvertFrom-Json
$testobj | Add-Member -Type NoteProperty -Name "RithwikKey" -Value "RithwikValue"
$rithtest = $testobj | ConvertTo-Json
Invoke-RestMethod -Method Put -Uri 'https://rith12.scm.azurewebsites.net/api/vfs/site/wwwroot/connections.json' -Body $rithtest -Headers $headers

enter image description here

After Updating in Logic App:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.