I'm having issues converting a curl command into Powershell Invoke-RestMethod. Ihave tried a number of different ways but i get error message: Invoke-RestMethod : The remote server returned an error: (401) Unauthorized.
The curl command that i need to convert for powershell:
curl -k -d "grant_type=client_credentials" -H "Authorization: Basic sometoken1234567890" https://api.vasttrafik.se:443/token
What i have tried so far:
$token = "c0a6dcae-e14b-3255-88a9-c83df513b314"
$headers = @{Authorization = "Basic "+[System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes("sometoken1234567890"))}
$body = ConvertTo-Json @{"grant_type" = "client_credentials"}
Invoke-RestMethod -Method Post -Headers $headers -Body $body -Uri "https://api.vasttrafik.se:443/token"
Also:
$body = @{
grant_type = "client_credentials"
}
$headers = @{
Authorization = "Basic "+[System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes("sometoken1234567890"))
Accept = "application/json"
ContentType = "application/json"
}
$params = @{
Method = "Post"
Uri = "https://api.vasttrafik.se:443/token"
Body = $body
Header = $headers
}
Invoke-RestMethod @params
I get the same error for both of them
I would be very much appreciated if someone could help