cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
9144
Views
5
Helpful
3
Replies

Help with Meraki API and Powershell

Christopheric12
Community Member

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.

image.png

1 Accepted Solution

Accepted Solutions

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

matt_uc
Level 6
Level 6

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!