Help with Meraki API and Powershell

SOLVED
Christopheric1
Conversationalist

Help with Meraki API and Powershell

I am having an issue using "Invoke-RestMethod" for Powershell to pull the clients (devices) list. I have setup the API and I am able to get some information like the Admins or the Network ID, Org ID, etc. I just can't seem to figure out how to pull my devices. I have looked at the documentation over and over and it is not working. I end up getting an Error 400: Bad request. 

Here is the documentation I followed to Get Clients: https://developer.cisco.com/meraki/api-v1/#!get-network-clients

 

Here is my Powershell script (scrubbed). Sorry, they don't have a code button for Powershell:

$APIKey = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
$orgid = "XXXXX"
$networkid = "N_XXXXXXXXXXXXXXXXXXXXXXXX"
$headers = @{
"Content-Type" = "application/json"
"Accept" = "application/json"
"X-Cisco-Meraki-API-Key" = $APIKey
}

Invoke-RestMethod -Method Get -Uri "https://api.meraki.com/api/v1/networks/$($networkid)/clients" -Headers $Headers

 

That is what I am thinking (per the documentation) should work. I am not sure where I am going wrong. I have Systems Manager only and I have devices that have been added to it. I would like that list.

2021-08-31_7-53-43.png

1 ACCEPTED SOLUTION

I actually got it. I just needed to add "/sm/devices" and that worked

Invoke-RestMethod -Method Get -Uri "https://api.meraki.com/api/v1/networks/$($networkid)/sm/devices"

 

Thanks!

View solution in original post

3 REPLIES 3
mlefebvre
Here to help

That code runs just fine in a non-SM network so that endpoint is likely not meant for SM, and what you are actually looking for may be one of these

 

https://developer.cisco.com/meraki/api-v1/#!get-network-sm-devices

 

https://developer.cisco.com/meraki/api-v1/#!get-network-sm-users

 

Exactly! If you want SM devices that's slightly different from network clients.

Get Network Clients

Operation Id:getNetworkClients

Description:List the clients that have used this network in the timespan

 

Get Network Sm Devices

Operation Id:getNetworkSmDevices

Description:List the devices enrolled in an SM network with various specified fields and filters

I actually got it. I just needed to add "/sm/devices" and that worked

Invoke-RestMethod -Method Get -Uri "https://api.meraki.com/api/v1/networks/$($networkid)/sm/devices"

 

Thanks!

View solution in original post

Get notified when there are additional replies to this discussion.
Welcome to the Meraki Community!
To start contributing, simply sign in with your Cisco account. If you don't yet have a Cisco account, you can sign up.