Simply use a for loop. You said you have 50+ input, so you have a couple of options in this case:
- Define a list in the
.py
file that holds all the networkd IDs (Not recommended).
- Create a file that contains all the network IDs (Recommended).
I'll illustrate option 2:
I assume you are using Meraki SDK v1.12.0 downloaded by running pip install meraki
from pprint import pprint
import meraki
API_KEY = ""
dashboard = meraki.DashboardAPI(API_KEY)
with open(file=r"network_ids.txt", mode="rt", newline="") as f:
network_ids = [id.strip() for id in f.read().splitlines() if id.strip()]
for network_id in network_ids:
network_device = dashboard.networks.getNetworkDevices(network_id)
pprint(network_device)
The network_ids.txt
file should be like: (each id
on a seperate line)
L_123456
L_789101
L_111213
To minimize the step of collecting network IDs and adding each ID on a seperate line in a file, you can get the IDs from an organization ID:
from pprint import pprint
import meraki
API_KEY = ""
dashboard = meraki.DashboardAPI(API_KEY)
# Any organization id
org_id = "549236"
# Get all networks for an organization
networks = dashboard.organizations.getOrganizationNetworks(org_id, total_pages="all")
# pprint(networks)
# loop through networks
for network in networks:
# Get network devices for each network ID
network_devices = dashboard.networks.getNetworkDevices(network["id"])
# Check if the network has devices
if network_devices:
print(f"*** Devices in Network: {network['name']} ({network['id']}) ***")
for device in network_devices:
pprint(device)
else:
print(
f"!!! No devices found for network: {network['name']} ({network['id']}) !!!"
)