0
votes

I am trying to get JSON details from an api using powershell. I do not have any expereince with power shell, but I guess Invoke-RestMethod would be helpful.

the api I am trying to use is :

api.spotcrime.com/crimes.json?lat=30.639155&lon=-96.3647937&radius=0.02&key=spotcrime-private-api-key

1
Have you tried it? You should be able to see documentation by running get-help invoke-restmethod or search for the documentation on the Internet.theglauber

1 Answers

0
votes

Please read the online documentation: Invoke-RestMethod

Here is a sample showing how to access the data returned from this API:

$uri = 'api.spotcrime.com/crimes.json'

$params = @{
    lat = '30.639155'
    lon = '-96.3647937'
    radius = '0.02'
    key = 'spotcrime-private-api-key'
}

$crimes = Invoke-RestMethod -Uri $uri -Body $params | 
    Select-Object -ExpandProperty crimes

$crimes | Format-Table -AutoSize

In this dataset we have an object named crimes which contains an array of records. Expanding the crimes object and storing it to a $crimes variable will allow us to work with the records more easily.

Notice how Invoke-RestMethod automatically detects and converts JSON into objects. No need to use ConvertFrom-Json.