Powershell and REST API

Hello All,

Does anyone have an example of a POST command through Powershell that works with the Graylog API?

I can create dashboards, but Widgets with POSH in the REST API give a generic error.

I can post code and results if anyone has a clue on how to proceed.

I have the JSON code form the api-browser…and that works…just not finding the right combo in powershell

OK - totally guessing here and it’s NOT Graylog but it’s a start… - below is googled from here

$json = @“{“alert_policy”:[{“enabled”:“true”}]”@

$headers = @{}
$headers[“X-Api-Key”] = “j65k423lj4k2l3fds”

Invoke-WebRequest -Uri “https://some/working/file.json” -Body $json -ContentType “application/json” -Headers $headers -Method Put

Appreciated…and I think that’s one of the ones I googled as well… but striking out…

This is the JSON code I need to POST through the API and it works through the API browser

{
“cache_time”: 10,
“description”: “Errors - 24 hrs”,
“type”: “SEARCH_RESULT_CHART”,
“config”: {
“interval”: “hour”,
“timerange”: {
“type”: “relative”,
“range”: 86400
},
“query”: “EventType:ERROR AND NOT EventID:5858”
}
}

AFter much trial and error… I found how to get POSH to convertto-json correctly.

FOr anyone searching this in the future:

@{
“cache_time”= 10;
“description”= “Errors - 24 hrs”;
“type”= “SEARCH_RESULT_CHART”;
“config”= [ordered]@{“interval”= “hour”;
“timerange”= @{
“type”= “relative”;
“range”= 86400
}
“query”= “EventType:ERROR AND NOT EventID:5858”
}
} | convertto-json

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.