I totally beginner with powershell and I need to create a curl command in powershell. Currently, in bash my script works fine with :
curl -X PATCH --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{ \
"foo":[ \
{ "foo1": "XXX","foo2": "XXX"}] \
}' 'My_URL?access_token=MY_TOKEN'
I try that :
$param = @{
Uri = "MY_URLS"
Method = "Post"
Body = '{"username":"XXX","password":"XXX"}'
ContentType = "application/json"
}
$token1 = Invoke-RestMethod @param | Select access_token
$token2 = $token1 -replace '\s','' | %{ $_.Split('=')[1];}
$token3 = $token2 -split "}" -replace '\s',''
$basicAuth = "$token3"
$headers = @{ Authorization = $basicAuth }
$uri2 = "https://URL"
Invoke-RestMethod -Method PATCH -Uri $uri2 -ContentType application/json -Headers $headers -Body '{"XXXX": [{ "foo1": "XXX","foo2": "XXX"}]}'
But it doesn't work... There is someone to tell me if there is a right way to do that ?
Thanks a lot !