get full org inventory with curl api

Joe-morris
New here

get full org inventory with curl api

I am trying to pull a full inventory using curl I am only getting 1000 of 2750 devices in our inventory. I am completely new to scripting and API.

 

Here is what I am doing so far...

/usr/bin/curl -L -H 'X-Cisco-Meraki-API-Key: [API KEY]' -H 'Content-Type: application/json' -X GET 'https://api.meraki.com/api/v1/organizations/[org id[/inventoryDevices' | jq ".[] | [.serial, .mac, .model, .orderNumber, .claimedAt] | @CSV" | sed -e 's/"//g' | tr -d '\\' > test.csv

 

I am getting all of the values of each line, but it stops at 1000. How do I get the full inventory?

2 REPLIES 2
PhilipDAth
Kind of a big deal

Re: get full org inventory with curl api

In the documentation, you'll see that it returns 1000 entries "per page".

https://developer.cisco.com/meraki/api-v1/#!get-organization-inventory-devices 

 

On the first call you'll get a token (sorry, not sure what it is in the header, but take a look) and then you call it again with the startingAfter parameter, and you get the next 1,000 entries.  Repeat until you have everything.

 

This will be a bit manual to do with curl ... Python would be a better bet.  The Python SDK does the pagination for you so you can ignore this.

https://developer.cisco.com/meraki/api-v1/#!python/meraki-dashboard-api-python-library 

Joe-morris
New here

Re: get full org inventory with curl api

Thanks for the reply. I planned to learn python. I thought this would be a quick ash script. Not turning out that way. lol When I run the

 

/usr/bin/curl -L -H 'X-Cisco-Meraki-API-Key: [key]' -H 'Content-Type: application/json' -X GET 'https://api.meraki.com/api/v1/organizations/[org ID]/inventoryDevices?perPage=1000&startingAfter=0;rel=first' > curl-test

 

I just get the data in json format. There is no header info with any tokens.

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.