Using PowerShell to Query WebApis

Hello All,

I’m trying to use the PowerShell module to query a WebApi and display data in a grid (can’t use the WebApi tile, because I need to request a token first).
I have a script that’s running locally, but regardless of what I do in SquaredUp I get “PowerShell host process returned neither a result nor error”.

Can someone point me to some examples on how to use the PowerShell module to query a WebApi?

Thx in advance - M.

Never tried it before for SQ, but likely you may want to have your script do a save a transcript then read on the transcript to see if any errors occurred when running under SQ.

1 Like

Hello Pascal,
pardon the question - how do I generate/save/view a “transcript”?

Thx in advance - M.

There’s a great article on Transcript logging here: Transcript Logging – Why you should do it « The Surly Admin

It depends on what you are trying to archive. I have a simple one running like this for a grid tile:
Invoke-RestMethod -Uri "https://<pathtosomeRSS-Feed>" -UseDefaultCredentials

There are examples on github like vmware: samples/dashboards/vmware-status at master · squaredup/samples · GitHub
VMware Status Dashboard - SquaredUp
And on the web site under resources:
Tips and tricks for building insightful visualizations with PowerShell - SquaredUp

Another option that we recommend for large data sets/scripts that might take a while to run is to have the script run somewhere and output to a CSV, then use a simple script in SquaredUp to read the CSV instead. This way, SquaredUp loads the data much faster, as it doesn’t have the bulk of auth and querying the data source.

1 Like

Hey guys - thank you so much for all of your answers. Obviously, the community is alive and active - awesome !!!

Turns out my issue was due to the json parser (I’m calling it that) in SquaredUp stumbling over a special character. Took me a while to figure out how to use the log and log settings to trace this.

Once I figured out (with help from Afreen from support) that it was a character that was causing this, I took care of it with this:

$content = $response | ConvertTo-Json
$content = $content -replace( [char]8220, “’”)
$content = $content -replace( [char]8221, “’”)
$finalresponse = $content | ConvertFrom-Json

Thx again to everyone!