az rest command working on v2.0.76 but not v2.1.0
See original GitHub issue
az feedback
auto-generates most of the information requested below, as of CLI version 2.0.62
Describe the bug
I used the az rest --method put --uri https://management.azure.com/subscriptions/{subscription_id}/resourceGroups/{resource_group}/providers/Microsoft.Web/sites/{app_name}/config/web?api-version=2019-08-01 --body '{\"properties\":{\"healthCheckPath\":\"/version\"}}'
with v2.0.76, it worked fine.
But when I tried the same command with v2.1.0, it gave this error: ERROR: Unsupported Media Type({"error":{"code":"UnsupportedMediaType","message":"The content media type '<null>' is not supported. Only 'application/json' is supported."}})
Then, I changed the command to az rest --method put --uri https://management.azure.com/subscriptions/{subscription_id}/resourceGroups/$RESOURCE_GROUP/providers/Microsoft.Web/sites/$APP_NAME/config/web?api-version=2019-08-01 --body '{\"properties\":{\"healthCheckPath\":\"/actuator/health\"}}' --headers '{\"Content-Type\":\"application/json\"}'
, The difference is to add application/json content type header. But I got another error: ERROR: not enough values to unpack (expected 2, got 1)
.
I also changed the format of header to --headers "Content-Type=application/json"
as per documentation(https://docs.microsoft.com/en-us/cli/azure/reference-index?view=azure-cli-latest#az-rest). But I got another error: ERROR: Bad Request({"error":{"code":"InvalidRequestContent","message":"The request content was invalid and could not be deserialized: 'Invalid property identifier character: \\. Path '', line 1, position 1.'."}})
.
I verified this --headers "Content-Type=application/json"
with v2.2.0, it works. Not sure what happens to v2.1.0.
I didn’t know why the same command working for v2.0.76, but not working for v2.1.0. Can someone figure it out? Many thanks in advance.
To Reproduce Please see above
Expected behavior The same command should work for both versions.
Environment summary
Additional context
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:8 (2 by maintainers)
For anyone find this when searching for:
It is most likely that you have 2 issues: Your json needs to be a single line json string, escaped. I had a multi line json in a variable in PowerShell, and when converting it to a single line and escaping the " (double qoute) to \" (slash double quote) the error went away.
For PowerShell quoting issue, please see https://github.com/Azure/azure-cli/issues/15529.