1

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 enter image description here

enter image description here

And the error enter image description here

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.

jan711
  • 21
  • 2

1 Answers1

0

SCOM Supports Basic Authentication as part of the Header. Here is an article on it: https://mevansit.blogspot.com/2017/03/scom-web-availability-monitoring-with.html

Blake Drumm
  • 137
  • 1
  • 7
  • Links to external resources are encouraged, but please [add context around the link](https://meta.stackexchange.com/a/8259) so your fellow users will have some idea what it is and why it’s there. Always quote the most relevant part of an important link, in case the target site is unreachable or goes permanently offline. [Answers that are little more than a link may be deleted](https://stackoverflow.com/help/deleted-answers) – Sabito stands with Ukraine Dec 24 '20 at 02:34