I made a view in the GUI, can click to it and get it to display export as CSV or JSON…but how can I just get this view with a simple powershell Invoke-RestMethod or INvoke-WebRequest, the only thing that is returning is the html of the login page.
I already use the api with powershell
$url = "https://fqdn/site/check_mk/api/v0/domain-types/host_config/collections/all"
$headers = @{
"Authorization"="Bearer $($Credential.UserName) $($Credential.GetNetworkCredential().Password)"
"Accept"="application/json"
"Content-Type"="application/json"
}
$iwr = Invoke-WebRequest -Uri $url -Headers $headers -Method Get
$response = $iwr.Content | ConvertFrom-Json
$hosts = $response.value
But it returns 600 hosts! My view in the GUI only has 226.
Some say you can add output=json to the url, but that didn’t work with this. I don’t want to use a hardcoded secret either as this is a script to be ran manually once in a while. Instead I use Get-Credential and pass the authentication via headers.
If there is no export=json that I can use with my method, then what can I use to filter out bad data from the all hosts api endpoint? the queries from the redoc seem incredibly obtuse.