我想使用 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的内容了。
但是,我使用相同的URL和Post/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 是什么?
我确实同意 @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:
In Logic App(Before Updating):
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
After Updating in Logic App: