I am having trouble with figuring out what should come under json body in the body when sending post rest api call to the scom server I have tried the below one.
{
"credentials":"<base64 coded text of credential>"
}
And here is the header and body
And this is the powershell script rest api request which I tried changing to postmain request
$server="servername"
# authentication part
$scomHeaders = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$scomHeaders.Add('Content-Type','application/json; charset=utf-8')
$bodyraw = "Windows"
$Bytes = [System.Text.Encoding]::UTF8.GetBytes($bodyraw)
$EncodedText =[Convert]::ToBase64String($Bytes)
$jsonbody = $EncodedText | ConvertTo-Json
$uri = "http:// $server/OperationsManager/authenticate"
$username = "username.com"
$password = ConvertTo-SecureString "paswword" -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential -ArgumentList ($username, $password)
$Request = Invoke-WebRequest `
-Method POST `
-Uri $uri `
-Headers $scomHeaders `
-body $jsonbody `
-Credential $cred `
-SessionVariable 'websession'
I also tried using the help of I want to fetch the SCOM alerts data. But I keep getting the error 401. I am passing the credentials right post. And still could not figure it out.