powershell http post REST API basic authentication powershell http post REST API basic authentication powershell powershell

powershell http post REST API basic authentication


I know this is an old thread, but for those who might stumble across this the invoke-restmethod is a much better, and simpler, vehicle for making API calls with PowerShell.

Build a parameter list as a hash table:

$params = @{uri = 'https:/api.trello.com/1/TheRestOfYourURIpath';                   Method = 'Get'; #(or POST, or whatever)                   Headers = @{Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("$($acctname):$($password)"));           } #end headers hash table   } #end $params hash table$var = invoke-restmethod @params

Your parameter hash table may differ slightly.

I actually haven't gotten this to work with Trello, but I have with GitHub, Serena Business Manager and Jira.


Your code looks good, I would try adding HTTP_AUTHORIZATION header for $webrequest like this:

$webRequest.Headers.Add("AUTHORIZATION", "Basic YTph");

Where YTph would be the base64encoded string for username : password.


Credentials property seems to be used for Windows authentication. Try using this function:Forcing Basic Authentication in WebRequestI would advise you in any case to use some web debugger, like Fiddler to see the difference between curl request and your request