PowerShell to Get Alerts through API with ticketid
I am trying to utilize the PowerShell cmdlets from PowerShell gallery to pull back alerts from our portal from a specific time windows and include the ##externalticketid## field.
In Python it says to update the queryParams with customColumns=%2523%2523externalticketid%2523%2523 but that does not seem to work in PowerShell.
Has anyone been able to utilize the API to pull back alerts and include the ##externalticketid## field so you can relate it to things like the ServiceNow INC being created for LogicMontior Alerts?
This is using API v2.
Jeffrey Batchelor
11 comments
LM User
Jeffrey Batchelor
OPSo it does look like I was only able to get the ticketid to come back in a single query pull was when it was connecting through v1.
The Python example and a similar one for PowerShell that I found were utilizing v1 to get the data.
Thanks.
Joseph Brett
Hey y’all, so the old V1 documentation does include this still.
However, it looks like the v2 and v3 swagger docs have been corrected to remove the “customColumns” being available as a parameter. This is due to performance impacts that parameter had on the “alert/alerts” api endpoint. Instead, if you need to pull custom columns you will need to make the API call to “alert/alerts/{ID}” where it is still a valid parameter.
https://www.logicmonitor.com/swagger-ui-master/api-v3/dist/#/Alerts/getAlertById
The URL encoding does remain the same as what is described in the v1 article:
%2523%2523externalticketid%2523%2523Joe Williams
Ok, I’ve attempted to replicate that and it doesn’t work in v2 or v3, in postman, unless i’m doing something wrong. So, i suspect a problem with the API and not not necessarily your code.
Same here in Python, Insomnia (poor mans Postman) and PowerShell.
LM User
Ok, I’ve attempted to replicate that and it doesn’t work in v2 or v3, in postman, unless i’m doing something wrong. So, i suspect a problem with the API and not not necessarily your code.
Jeffrey Batchelor
OPThe example at the bottom of this page shows the python that can get the ticket id back:
https://www.logicmonitor.com/support/rest-api-developers-guide/v1/alerts/get-alerts#sc-header-698
LM User
Yeah, but i can’t get it to work in postman either, so i’m questioning if it actually works in python or if we’re relying on the documentation that claims that it works or if Jeff has it working in a python script. If so, i’d like to see what the query params are in python so i can replicate in postman. Postman has autocode generation. Pick the language and it’ll write a simple script to do your api call, showing what the syntax should be for the query params.
Joe Williams
If it works in python and not powershell, this normally goes down to url encoding. Some python libraries auto url encode. So most likely your params are invalid due to lack of encoding.
LM User
Hm, if it’s working in python, what’s the URL and headers that are getting sent (minus authentication header)? If it works in python, that means it should work in postman, which means it should work in powershell. We just gotta get the queryParams right. Do you have working code for python?
Jeffrey Batchelor
OPI have opened a support ticket about how to do this in PowerShell. And the ##externalticketid## field is something that does work in API v2 in Python; just does not seem to work the same way in PowerShell.
Hopefully support will be able to provide an PowerShell example.
LM User
Use APIv3. v1 and v2 will get cut off at some point and you don’t want to have to rebuild it.
If you can’t get something to work in powershell, take your code out of the equation by issuing the call in a rest client like postman.
I tried this in v3 and it doesn’t work, even in postman. This means it’s not a powershell issue, but probably that they changed the way to get at the externalticketid in v2 and v3 of the api and didn’t update their documentation/examples from the v1 stuff. I would recommend you reach out to support. Let them know you attempted the documented solution and what might be wrong with your syntax. When you find out what the issue is, ask them to submit a doc ticket to have the documentation updated (and let us know here).