02-19-2024 01:56 PM
Im trying to test getting info from my Org to learn building scripts.
I want to get the list of switch ports from a specific Network ID. I am able to pull the device ports if I use the switch's serial number:
response = dashboard.switch.getDeviceSwitchPorts(
serial
)
print(response)
https://developer.cisco.com/meraki/api-v1/get-device-switch-ports/
Im trying to expand upon this by getting the switch ports from a net ID
import meraki
API_KEY = 'c4............................................'
dashboard = meraki.DashboardAPI(API_KEY)
organization_id = 'XXXXXX'
# Get the list of networks in your organization
networks = dashboard.organizations.getOrganizationNetworks(
organization_id, total_pages='all'
)
# Find the network that you want
network_id = 'L_6................................'
# Get the list of switchports
switchports = dashboard.switch.getDeviceSwitchPorts(
network_id
)
# Print the list of switchports
for switchport in switchports:
print(switchport)
I get an error
ERROR > switch, getDeviceSwitchPorts - 404 Not Found, b''
02-19-2024 02:39 PM
Have you tried this API?
https://developer.cisco.com/meraki/api-v1/get-organization-switch-ports-statuses-by-switch/
02-19-2024 03:30 PM
Hi ,
https://developer.cisco.com/meraki/api/get-device-switch-ports/
/devices/{serial}/switch/ports
You can't input a Network ID , it requires a Serial number. You would be better using the Org-Wide call that alemabrahao has suggested and filter the json received or filter with the parameter networkids.
02-20-2024 10:52 AM
Thank you both.
HMM. I was playing with this to add
# Filter the devices to only include switches
switches = []
for device in devices:
if device["model"].startswith("MS"):
switches.append(device)
# Print the list of switches
for switch in switches:
print(switch["serial"])
this gets me the serial of each switch.
Can I use this output in the operations you both have provided?
I assume I am going need to build an array or something
02-20-2024 07:14 PM
So you want to get the list of switch ports by network ID?
API_KEY = 'xxxx'
ORG_ID = 123
NET_ID = L_123
02-21-2024 07:16 AM
WellyHartanto, Thank you.
Yes, I have about 50 networks that I manage. I want to be able to get the ports in each network so I can say, bounce all ports in a specific vlan. We have "homemade" PoE devices in certain vlans that need bounced every so often if they lose connectivity to a server.
I also want to look to disable unused ports after XX number of days.
I hope Im on the correct path to be able to accomplish those tasks?
02-21-2024 07:31 AM
Yes it can be done via API.
Take a look at the ouput when you make the API call for switch ports to determine the port VLAN.
For unused port, this thread may help: https://community.meraki.com/t5/Developers-APIs/Find-Unused-Ports-And-Shut-them-Down/m-p/223886/highlight/true#M9740
02-21-2024 08:39 AM
WellyHartanto,
question about the cycle ports script...
timespan=(31*24*60*60))
Is this 31 days, then 24 hrs in a day, 60 min in an hour, 60 sec in a minute?
so if you wanted a different # of days you just need to change the 31?
02-21-2024 08:30 PM
the timespan parameter is in seconds and a maximum of 31 days (you may want to read the documentation thoroughly)
02-21-2024 11:28 AM
Looks like "getOrganizationDevices" does not handle stacked switches. When I run it only returns the primary switch ports, and not the member switch ports.
02-21-2024 08:32 PM
Based on the documentation, I disagree.
02-22-2024 06:45 AM
HMM. ok. Ill have to take another look. thank you!
02-23-2024 12:22 PM
I found it. the output splits the stacked switches, and put my 3rd switch which is standalone sandwiched in between.
Thank you again!
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide