I'm trying to update device switch ports via the Python API, but it doesn't work. So I tried the code snippet from the docs page and filled all fields with values. But I only get the Response "HTTP response not OK".
Here the Python code I copied from the Meraki Developer Hub.
Does anybody have an idea, what's the problem?
from meraki_sdk.meraki_sdk_client import MerakiSdkClient
from meraki_sdk.models.update_device_switch_port_model import UpdateDeviceSwitchPortModel
from meraki_sdk.models.udld_enum import UdldEnum
from meraki_sdk.exceptions.api_exception import APIException
x_cisco_meraki_api_key = '------ API KEY ------'
client = MerakiSdkClient(x_cisco_meraki_api_key)
switch_ports_controller = client.switch_ports
collect = {}
serial = 'Q2GW-4ZDP-xxxx'
collect['serial'] = serial
number = '20'
collect['number'] = number
update_device_switch_port = UpdateDeviceSwitchPortModel()
update_device_switch_port.name = 'Test Port'
update_device_switch_port.tags = 'test'
update_device_switch_port.enabled = True
update_device_switch_port.mtype = 'access'
update_device_switch_port.vlan = 221
update_device_switch_port.voice_vlan = 21
update_device_switch_port.allowed_vlans = 'all'
update_device_switch_port.poe_enabled = True
update_device_switch_port.isolation_enabled = False
update_device_switch_port.rstp_enabled = True
update_device_switch_port.stp_guard = 'disabled'
update_device_switch_port.access_policy_number = 1234
update_device_switch_port.link_negotiation = 'Auto negotiate'
update_device_switch_port.port_schedule_id = '1234'
update_device_switch_port.udld = UdldEnum.ENUM_ALERT_ONLY
update_device_switch_port.mac_whitelist = ['34:56:fe:ce:8e:a0']
update_device_switch_port.sticky_mac_whitelist = ['34:56:fe:ce:8e:b1']
update_device_switch_port.sticky_mac_whitelist_limit = 5
update_device_switch_port.storm_control_enabled = True
collect['update_device_switch_port'] = update_device_switch_port
try:
result = switch_ports_controller.update_device_switch_port(collect)
except APIException as e:
print(e)
Try getting the switch port status and then dumping the fields. Compare them to the format you are using. Sometimes things are formatted different to how you expect.
I can't remember weather the API is case sensitive, so compare "Any" and "any" differences.
That's what I though too, so then I just copied the code snippets from the Meraki developer page and adjusted the values of clan and voice clan, added my API key and put it to run. I hoped the samples are tested by the developers.
https://developer.cisco.com/meraki/api/#/python/api-endpoints/switch-ports/update-device-switch-port
I also read the switch port via "get_get_device_switch_port()" using the same collect dictionary, that's working fine.
I have inserted in the get- and update-function a print. Then I'll try the REST-API call and will compare this all.
Thank you
Agree with Phillip. Looks like you have a few non true/false statements that aren't set as a string/list/etc. Specifically your vlan and voice vlan.
That's what I thought to. So I prepared the code via the sample on the Meraki developer page https://developer.cisco.com/meraki/api/#/python/api-endpoints/switch-ports/update-device-switch-port
added my api-key and run it, same error occurred.
I will now analyze it a bit deeper, as I've answered Philip.
Thank you.