jsonpowershellazure-logic-appsazure-rest-api

Method Not Allowed when using the REST API to update the json view on connections for Logic App


I want using the REST API to update the json view, just like I asked in this post:

enter image description here

Since the content in the json view is a lot and dynamic, I want use Get to get the content before modifying it, and then simply modify Json view with this body update to overwrite the original json view.

Now, I could using develop tool F12 to get the content with below URL:

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

Then I can get the content of the Json View.

However, I using the same URL with Post/Put method, like:

$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

The result is:

The remote server returned an error: (405) Method Not Allowed.

Even if I using another URL:

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

Still the same error.

So, my question is that what is the correct REST API URL to modify the json view?


Solution

  • I do agree with @10p that cli command is correct but to get the content using PowerShell use below script:

    $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