Update multiple devices in different networks

SOLVED
conwaybradley
Conversationalist

Update multiple devices in different networks

I'm attempting to update multiple access point's tags in multiple networks at the same time. I know you can do this in the dashboard as long as they are in the same network. But I'm trying to update the tags of multiple access points in different networks. I might be missing a way to do this via the dashboard but after looking through it and the documentation I can't seem to find a way.

 

I'm now trying to complete this using python and meraki's dashboard API. Would it be possible to get the inventory of an organization, then using that list to update the devices with new information? For example I'd use “meraki.getorginventory” to provide a list of AP’s to update when doing a “meraki.updatedevice”. Any and all assistance on this is greatly appreciated!

1 ACCEPTED SOLUTION
HodyCrouch
Building a reputation

If you're trying to add a tag or modify the tag list, note that the inventory API does not include the current set of tags for each device.

 

If you update the device attributes (/networks/[networkId]/devices/[serial]), you will overwrite any existing tags.  If that's okay with you, go for it.  Otherwise, you will need to do a bit more work.  Note that the tags parameter is a space-delimited set of tags.

 

Instead, you can call the inventory API to get the list of devices, then get the device attributes for each device, parse the tag list and make any necessary changes, and then update the device attributes.  It's really not that bad, but does require a little more code.

 

One more thing, Meraki's APIs limit how quickly you can call them.  If you're updating a lot of devices, make sure you throttle the requests.  I think the official limit is 5 per second, although if I configure any higher than 3 per second, I get occasional failures.

View solution in original post

22 REPLIES 22
wifijanitor
Meraki Employee
Meraki Employee

so digging into the that call, it looks like you can. the help(meraki) shows ``` updatedevice(apikey, networkid, serial, name=None, tags=None, lat=None, lng=None, address=None, move=None, suppressprint=False) # Update the attributes of a device # https://api.meraki.com/api_docs#update-the-attributes-of-a-device ``` if you click on the link to the API documentation, you can see what the call looks like to update the tags. keep in mind that you are updating per device, per network ``` updatedevice(apikey, networkid, serial, name=None, tags=None, lat=None, lng=None, address=None, move=None, suppressprint=False) ```
HodyCrouch
Building a reputation

If you're trying to add a tag or modify the tag list, note that the inventory API does not include the current set of tags for each device.

 

If you update the device attributes (/networks/[networkId]/devices/[serial]), you will overwrite any existing tags.  If that's okay with you, go for it.  Otherwise, you will need to do a bit more work.  Note that the tags parameter is a space-delimited set of tags.

 

Instead, you can call the inventory API to get the list of devices, then get the device attributes for each device, parse the tag list and make any necessary changes, and then update the device attributes.  It's really not that bad, but does require a little more code.

 

One more thing, Meraki's APIs limit how quickly you can call them.  If you're updating a lot of devices, make sure you throttle the requests.  I think the official limit is 5 per second, although if I configure any higher than 3 per second, I get occasional failures.

MarkD_BT
Getting noticed

Hey Conway,
I utilise the API in this maner and have been utilising it for a while making updates accross orgs and networks. IT might not be the cleanest way to acheive and i use Powershell to get and post information but the premise would be the same.
I extract all information against the Org using the networks url. Placing the results into a CSV.
https://api.meraki.com/api/v0/organizations/[organizationId]/networks
Using this list i then i extract device information into another csv looping the results in the network list to create a new one with devices
https://api.meraki.com/api/v0/networks/[networkId]/devices
You can then update this CV with information Tags/Address's/Address details/Notes (this is not shown on the doc but you get notes).
Then i would use this updated csv looping through posting the details and setting the url with varibles from that https://api.meraki.com/api/v0/networks/[networkId]/devices/[serial]

Let me know if you need more information.

hi, could you provide some tech info on how to process these loops. i'm quite new to API and the programming and could use some pointers. i've use POSTMAN with some success on single queries but it's not clear on how to process mutliple /looped updates.

 

I need to update SNMP settings on over 400 networks

MarkD_BT
Getting noticed

Hi 5ghz,

 

I don't think postman allow for multiple queries at the same time so your going to have to look at some programing language to achieve this. I perform it using windows powershell as it was available on my works machine and not locked down from use or needing any other software installing. My loops are ForEach statements to look at each org/network/device in an array.

 

get orgs > foreach org > get network > foreach network > get devices (or what ever information you are after)

 

Are your snmp settings going to be the same against all your networks or is there individual credentials for them. Also is this going to be published to every network you can see or only certain ones. As you could tackle them slightly different depending on that. Depending if you have to filter on certain sites and or have different information to publish to that list.

 

 

conway
Conversationalist

Meraki has some pretty detailed python scripts on their Github page. (https://github.com/meraki). Just like how MarkD_BT stated, you will need a loop statement to go through each network. If you need a further example, Meraki's script on this page (https://github.com/meraki/provisioning-lib/blob/master/python-3.5-api-module/sample-tagdevices.py) is how I solved my original problem. I was able to edit it to fit my needs and update all APs in my organization that contained a certain naming scheme. 

thanks for this. I started looking at the powershell options and it does look like for my example it's probably the best path to follow. I'm not a programmer so there is a fair bit to digest.

MarkD_BT
Getting noticed

Hey 5ghz,

 

Is it the same details against every network you use. I'm not a native programmer either but like tinkering happy to snap something together that will allow you to do your updates.

 

quick one just to show how to get all your networks against all your orgs

These utilise GET commands so only reading data not writing.

 

 

#### make sure powershell runs script as tls1.2

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

$apikey = "ENTER YOUR API KEY IN HERE"

$header = @{

"X-Cisco-Meraki-API-Key" = $apikey

"Content-Type" = 'application/json' }

 

## Define the tables for storing devices used later ##

$networklist_all = @()

 

$resourceOrgs = "https://api.meraki.com/api/v0/organizations"

$resultOrgs = Invoke-RestMethod -Uri $resourceOrgs -Method GET -Header $header

ForEach ($Org_Meraki in $resultOrgs) {

$FindOrgid = $Org_Meraki.id

$FindOrgName = $Org_Meraki.name

$GetNetworks = "https://api.meraki.com/api/v0/organizations/$FindOrgid/networks/"

Try {

$resultGetNetworks = Invoke-RestMethod -Uri $GetNetworks -Method GET -Headers $header

 

}

 

catch [System.Net.WebException] {

$Request = $_.Exception

Write-Warning "No Networks In This Organisation '$FindOrgName'"

Continue

 

}

$resultGetNetworksSorted = $resultGetNetworks | Sort-Object name

ForEach ($Network_Meraki in $resultGetNetworksSorted) {

$Selected_network = New-Object psobject

$Selected_network | Add-Member -MemberType NoteProperty -Name id -Value $Network_Meraki.id

$Selected_network | Add-Member -MemberType NoteProperty -Name name -Value $Network_Meraki.name

$Selected_network | Add-Member -MemberType NoteProperty -Name timeZone -Value $Network_Meraki.timeZone

$Selected_network | Add-Member -MemberType NoteProperty -Name tags -Value $Network_Meraki.tags

$Selected_network | Add-Member -MemberType NoteProperty -Name type -Value $Network_Meraki.type

$Selected_network | Add-Member -MemberType NoteProperty -Name disableMyMerakiCom -Value $Network_Meraki.disableMyMerakiCom

$Selected_network | Add-Member -MemberType NoteProperty -Name disableRemoteStatusPage -Value $Network_Meraki.disableRemoteStatusPage

$Selected_network | Add-Member -MemberType NoteProperty -Name OrgName -Value $FindOrgName

$networklist_all+=$Selected_network

 

}

}

$networklist_all

 

Hi MarkD_BT,

 

Yes settings will be the same across all networks. I had a go today and managed to get a list of all network ids into a variable, ready to be used in a for loop. I'll look at your code example too as it looks like I can learn a lot from this. Thanks so much for your help.

MarkD_BT
Getting noticed

Hey 5ghz,

 

how you getting on with this any joy was busy most of yesterday but might be able to cobble something together quickly if it helps.

think i'm good, thanks for your help. just playing around with the looping now.

Hi,

 

are you able to still help with this request? i need to pull the network IDs out of the original script and then feed to an update / put script to update the same SNMP settings to every network.

MarkD_BT
Getting noticed

@5ghz 

Hi,

 

You still needing help with this i've not been online for a while and been busy but will have a bit time soon if your still needing some pointers.

thanks for replying. I used POSTMAN in the end as it was quite easy to work out how to setup a loop using collection runner. i grabbed a list of network IDs into a csv and then this was parsed through.

@5ghz 

 

Hello, would you be able to explain how you accomplished this?  I am trying to update SSID settings (name, psk) across multiple networks (same settings everywhere) but not understanding how to build a collection for multiple updates to multiple networks.  I have Postman installed and have successfully sent single PUT requests.

 

Thanks!

Hi,

 

You will need to use the postman collection runner which will allow you to loop one of your single instances that you have tested already.

 

your case sounds similar where you want the same setting across multiple networks so should be pretty easy once you understand how postman wants you to set this up. It took me a while as the documentation wasn’t very good at the time, but seems a bit better now.

 

https://blog.getpostman.com/2018/04/11/looping-through-a-data-file-in-the-postman-collection-runner/

 

let me know if this link helps you or not, and if you need some more detail I can put something together to help.

 

also if you have google sheets access you can use the built in Meraki tools add on to help with API queries. Worth a look to see if there is anything useful in there too.

@5ghz 

 

Hello, yes some extra detail would be great.  I'm trying to use the PUT below to simply change the first SSID name across 2 different networks in a .csv.  Am I correct that the csv should only include the 2 variables in the 1st image (networkId, number) and the body of the saved request called in the runner should have the static settings I want (ssid name)?

 

ssidPUT1.jpg

ssidPUT2.jpg

 

My .csv:

networkIdnumber
L_XXXXXXXXXXXXXXX0
L_YYYYYYYYYYYYYYY0

 

This is what I get when I try to run the collection:

ssidPUT3.jpg

 

Thanks!

hi,

 

You csv if you open in notepad should read like this;

 

networkid,number

Nxxxxxxxx,0

Nxxxxxxxx,0

 

If you are sure that the SSID is always ID 0 then you could just hard-code this in the command, so you would only need to have the list of network ids in your csv.

 

the reason it's failing is because the put statement requires the variables, whereas you have them in the path variables section. it should read:

 

https://api.meraki.com/api/v0/networks/{{networkId}}/ssids/{{number}}

 

api.GIF

api.GIF

 

if you delete where it says :networkid and type {{networkid}} you'll see the path variable disappear from the params section. then either repeat for the :number or set this value to 0 if your ssid is always 0.

 

hope this helps.

 

thanks

 

 

 

 

 

 

That makes sense, but somehow still cant get it to work.  I have statically set 0 as the ssid number, so I only have the networkId to deal with in the csv.  When I run the collection, I get a 404 error (I am selecting the same Env that I use for individual requests)

collection1.jpg

collection2.jpg

collection3.jpg

collection4.jpg

 

Thanks!

 

 

I would delete the path variable ’number’ completely, and either have this

 

https://api.meraki.com/api/v0/networks/{{networkId}}/ssids/{{number}}

 

with your csv having the ssid number, or use this 

 

https://api.meraki.com/api/v0/networks/{{networkId}}/ssids/0

 

404 is page not found so it’s the syntax of the command not enumerating to a valid page.

Strange, still getting the 404 error, I've gone with https://api.meraki.com/api/v0/networks/{{networkId}}/ssids/0 , but no luck (I tried the other method with {{number}} as well).

 

It looks like the csv data is not getting passed through to the variable.

 

collection5.jpg

 

Thanks

Success! Not sure why exactly, but my computer crashed and when I reopened excel and imported/resaved the csv, my collection ran successfully.  Thank you very much @5ghz!

 

 

Get notified when there are additional replies to this discussion.