0

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?

3
  • I don't understand why you insist on using a different URL if the answer to your previous question contains the following URL - both GET and PUT have been tested by me personally: https://<logic-app-name>.scm.azurewebsites.net/api/vfs/site/wwwroot/connections.json Commented Apr 15, 2024 at 14:45
  • @10p, That's because I couldn't get the correct results using the URL you shared, so let me reply to you in your previous post. Commented Apr 16, 2024 at 1:32
  • I understand, but normally creating duplicate questions in StackOverflow is not encouraged as they dilute and scatter knowledge on the site, making it harder for users to find the right answer. It is preferable to have all answers to one question in one place. Commented Apr 16, 2024 at 13:59

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks for your answer, but as I test your code in the azure powershell task in the azure devops, but I get the error "The remote server returned an error: (403) Forbidden." for the get method. But based on my testing in the question, I should have the permission.
My script is right, I have got desired result too, you can check it clearly, Did you use exactly same?
Check whether your DevOps service principal has proper RBAC roles under Azure subscription or not
Yes, I also found that SP do not have the permission logic app contributor.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.