Postman

Meraki-Beast
Comes here often

Postman

Hello Community,

 

I am just starting to use Postman, I was able to successfully retrieve data from Meraki but I'm unable to filter that data although there are parameters available to do such an action. Anyone familiar with doing this? 

 

Is there a way to export this data to a CSV or eventually a database of some sort?

7 Replies 7
ww
Kind of a big deal
Kind of a big deal

i think its better to use python if you want to use databases csv filtering etc.

T1
Building a reputation

I use Powershell for API calls and data analysis. Code below will fetch all devices (with all available fields) from a particular network and store them as array variable $data. You can dump them as .csv with something like this: $data | Export-CSV "c:\mdm.csv" -NoTypeInformation

 

 

# Meraki API key
$api_key = 'your_key'

# Ensures that Invoke-WebRequest uses TLS 1.2 otherwise request will fail
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

$network_id = 'N_0000' #MDM network ID
$organizationID = '00000'

$header = @{
        
    "X-Cisco-Meraki-API-Key" = $api_key
    "Content-Type" = 'application/json'
}

$api = @{
    "endpoint" = 'https://dashboard.meraki.com/api/v0'
}

$api.url = '/networks/' + $network_id + '/sm/devices?fields='
$api.param = 'ip,systemType,availableDeviceCapacity,kioskAppName,biosVersion,lastConnected,missingAppsCount,userSuppliedAddress,location,lastUser,publicIp,phoneNumber,diskInfoJson,deviceCapacity,isManaged,hadMdm,isSupervised,meid,imei,iccid,simCarrierNetwork,cellularDataUsed,isHotspotEnabled,createdAt,batteryEstCharge,quarantined,avName,avRunning,asName,fwName,isRooted,loginRequired,screenLockEnabled,screenLockDelay,autoLoginDisabled,hasMdm,hasDesktopAgent,diskEncryptionEnabled,hardwareEncryptionCaps,passCodeLock'
$api.scope = $Null # 'Change to '&scope=withAny,your_tag' to fetch devices with specific tag'
$uri = $api.endpoint + $api.url + $api.param + $api.scope 
$data = @((Invoke-RestMethod -Method GET -Uri $uri -Headers $header).devices)
Meraki-Beast
Comes here often

This is exactly what I need!! I am having a difficult time executing this though. I have inputted my key, network and ORG ID. I think it's just a syntax issue. When I execute the following command: $data | Export-CSV "c:\mdm.csv" -NoTypeInformation the CSV file is created but no data is inside.

 

What am I doing wrong?

T1
Building a reputation

Are you getting any errors at all? Is $data variable polulated with data? Technically I'm getting an "access denied" error when trying to save .csv to root folder, so usually it looks like $data | Export-CSV "c:\users\blah\Documents\mdm.csv" -NoTypeInformation
Meraki-Beast
Comes here often

I did change the path from the Root of C, I'm getting the below error message:

 

Export-Csv : Cannot bind argument to parameter 'InputObject' because it is null.
At line:1 char:9
+ $data | Export-CSV "c:\users\b\Documents\mdm.csv" -NoTypeInforma ..
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Export-Csv], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.ExportCsvCommand

T1
Building a reputation

Looks like you are not getting anything out of Meraki.

 

Can you comment this line:
$data = @((Invoke-RestMethod -Method GET -Uri $uri -Headers $header).devices)

and run this instead:
Invoke-RestMethod -Method GET -Uri $uri -Headers $header

Do you see any output at all?

Also, you could run Invoke-WebRequest, rather than Invoke-RestMethod to check HTTP status codes etc: 
$test = Invoke-WebRequest -Method GET -Uri $uri -Headers $header
    $test | fl




PeterJames
Head in the Cloud

@T1 - I would never have thought of using PowerShell for an API call! Great post! 

 

Now time to process my 'I feel old' feelings...Meh, batch job later!

 

Thank you,
Peter James

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.
Labels