Here at Automation Logic we spend a lot of time talking to a huge variety of APIs (RESTful or otherwise). So it’s nice to know that PowerShell makes it easier than ever to send API calls from the Windows command line. Here’s a recent example we’ve used to talk to the HP Operations Orchestration (OO) API. You’ll need at least PowerShell version 3.

$username = "username"
$password = "password"
$auth = $user + ':' + $password
$Encoded = [System.Text.Encoding]::UTF8.GetBytes($auth)
$EncodedPassword = [System.Convert]::ToBase64String($Encoded)
$headers = @{"Authorization"="Basic $($EncodedPassword)"}
$contentType = "application/json"
$url = "https://<hostname>:8443/oo/rest/latest/executions"

$flowInput = New-Object PSObject -Property @{
"inputName" = "inputValue"
}

$flow = New-Object PSObject -Property @{
"uuid" = "flowUUID"
"runName" = "Run name of the follow"
"inputs" = $flowInput
}
$json=ConvertTo-Json $flow

$response = Invoke-RestMethod -Uri $url -Credential $creds -ContentType
write-host $response

For those wondering what PowerShell is doing under the hood, here’s the rough equivalent as a cURL command:
curl -H "Content-Type:application/json" -H "Accept:application/json" -X POST -d'{"uuid":"flowUUID","runName":"Run name of the flow","logLevel":"DEBUG", "inputs":{"inputName":"inputValue"}}' https://<hostname>:8443/oo/rest/latest/executions --user 'username:password'

< Back