Doug Tarr

Using powershell 3 Invoke-RestMethod with Basic Authentication and JSON

This took me a remarkably long time to figure out.  Enjoy!

$user = "myuserid"
$pass= "mypass"
$uri = "https://myresturi.com/api/something"

$json = "{
            ""foo"" : ""bar""
          }" 

$secpasswd = ConvertTo-SecureString $password -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential ($pass, $secpasswd)

Invoke-RestMethod -Uri https://api.intercom.io/v1/users -Method Post -Credential $cred -ContentType "application/json" -Body $json