I am using powershell (specifically Azure CLI) to get data from a service, add a value to a list and send a patch/post to an URL.
This is the URL to get the list of data:
$uriList = az rest --method get --uri "https://graph.microsoft.com/beta/applications/$objectId" --header "$header" --query spa.redirectUris | ConvertFrom-Json
This returns an array of strings.
['a', 'b', 'c', 'd', 'e']
if ($uriList -notcontains "f") {
$uriList += "f"
}
$uriListJSON = $uriList | ConvertTo-Json
Above, I have added "f" to the array and I want to send it to the url as follows:
$body = "{spa:{redirectUris: $uriListJSON}}"
az rest --method patch --uri "https://graph.microsoft.com/beta/applications/$objectId" --headers "$header" --body "$body"
I get an error:
Unable to read JSON request payload. Please ensure Content-Type header is set and payload is of valid JSON format."
Please advice on what I am doing wrong. I outputted uriListJSON to a file and ran it against a json validator and it passed.
When I hardcode everything to a url like
az rest --method patch --uri "https://graph.microsoft.com/beta/applications/$objectId" --headers $header --body "{spa: {redirectUris: ['a', 'b', 'c', 'd', 'e', 'f']}}"
it works like a charm.