Azure REST API for SQL not working for CLI but works for Post Man
See original GitHub issueDescribe the bug
Command Name
az rest
Errors:
Bad Request({"error":{"details":[{"code":"InvalidResourceIdSegment","message":"","target":"parameters.properties.weeklyRetention"}],"code":"InvalidResourceIdSegment","message":"The 'parameters.properties.weeklyRetention' segment in the url is invalid."}})
To Reproduce:
Steps to reproduce the behavior. Note that argument values have been redacted, as they may contain sensitive information.
# Language : PowerShell
$server = "YOUR_AZURE_SQL_SERVER"
$database = "YOUR_AZURE_SQL_DATABASE"
$weeklyRetention = "P2W"
$policyName = "default"
$apiVersion = "2019-06-01-preview"
$srvs = az sql server list --query "[?name=='$server']" | ConvertFrom-Json
$srv = $srvs[0]
$dbs = az sql db list --resource-group $srv.resourceGroup --server $srv.name --query "[?name=='$database']" | ConvertFrom-Json
$db = $dbs[0]
# This works 👍
az rest --method "GET" --uri "$($srv.id)/databases/$($db.name)/backupLongTermRetentionPolicies/$($policyName)?api-version=$apiVersion" | ConvertFrom-Json
# This Fails 👎
az rest --method "PUT" --uri "$($srv.id)/databases/$($db.name)/backupLongTermRetentionPolicies/$($policyName)?api-version=$apiVersion" --header "Content-Type=application/json" --body "{ ""properties"": { ""weeklyRetention"": ""$weeklyRetention"" } }" --debug
Expected Behavior
Should update with 202
response:
{
"operation": "UpsertDatabaseBackupArchivalPolicyV2",
"startTime": "2020-05-05T15:04:16.397Z"
}
Environment Summary
Windows-10-10.0.14393-SP0
Python 3.6.6
azure-cli 2.2.0
Additional Context
Also note that setting backupShortTermRetentionPolicies
on the same resource works without a problem:
az rest --method "PUT" --uri "$($srv.id)/databases/$($db.name)/backupShortTermRetentionPolicies/$($policyName)?api-version=$apiVersion" --header "Content-Type=application/json" --body "{ ""properties"": { ""retentionDays"": 35 } }"
So I know it’s not an issue with the headers or how I pass the JSON body.
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Azure REST APIs with Postman (2021) - YouTube
Here's the 2021 edition of my very popular Azure REST APIs with Postman video and blog posts.Lots of things have changed since my...
Read more >Azure REST APIs with Postman (Dec 2017) - Jon Gallant
The Azure REST APIs require a Bearer Token Authorization header. The docs do a great job explaining every authentication requirement, but do ...
Read more >Calling Azure REST API via curl - Davide Mauri - Medium
Calling Azure REST API via curl. A straightforward post to invoke Azure REST API via simple HTTP calls. In these days I needed...
Read more >Issues using rest api body in powershell with Azure cli
You can use powershell CMD Invoke-AzRestMethod with put method it works similarly as az rest method. Share.
Read more >GET REST API works with postman but gives error from VB ...
but everytime same exception. my codes are working if i put same API on another web server with https but it does not...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Typical PowerShell issue https://github.com/PowerShell/PowerShell/issues/1995. 😕
This command should fail as well because the quote quotes are lost:
Please see my latest PR https://github.com/Azure/azure-cli/pull/13419 where I am trying to make this clear and providing some workarounds.
add to S170