cycleDeviceSwitchPorts - 400 Bad Request, {'errors': ["'ports' must be an array"]}

Solved
AhmedJawad
Getting noticed

cycleDeviceSwitchPorts - 400 Bad Request, {'errors': ["'ports' must be an array"]}

Hi All, 

 

  I'm getting the error in the subject when I try to cycle switch port. i can apply or remove the access policy using the same for loop with no issues. But when I try to cycle I'm getting the error. below is my code. 

 

any idea please? 

 

def ports(Net_ID,vlan=None,accesspol=None😞
    Devices = dashboard.networks.getNetworkDevices(Net_ID)  
    for device in Devices:
        #print(device['serial'])
        port1 = dashboard.switch.getDeviceSwitchPorts(device['serial'])
        for port in port1:
            # print(port)
            if port['accessPolicyType'] != 'Open' and port['vlan']== vlan and port['type'] != 'trunk':
                port_upd= dashboard.switch.updateDeviceSwitchPort(device['serial'], port['portId'], accessPolicyType = 'Open' ) # 'Custom access policy') #accessPolicyNumber = accesspol ,accessPolicyNumber = accesspol )
                print("Name:  {} \t Switch_Serial: {} \t PortNumber: {} \t VLAN: {} \t accessPolicy: {} ".format(device["name"], device["serial"], port['portId'], port["vlan"], port["accessPolicyType"]))
                port_Cycle = dashboard.switch.cycleDeviceSwitchPorts(device['serial'], port['portId'])
1 Accepted Solution
RaphaelL
Kind of a big deal
Kind of a big deal

Hi ,

 

If you look at the documentation the input must be an array : https://developer.cisco.com/meraki/api-v1/#!cycle-device-switch-ports

 

like : ports = ['1', '2-5'] or simply ports = ['1'] while you are probably passing a string from getDeviceSwitchPorts ( portId = "1" ) 

 

There are  many ways to fix it.  

 

portlist = []

portlist.append(port['portId'])

port_Cycle = dashboard.switch.cycleDeviceSwitchPorts(device['serial'], portlist)

View solution in original post

3 Replies 3
RaphaelL
Kind of a big deal
Kind of a big deal

Hi ,

 

If you look at the documentation the input must be an array : https://developer.cisco.com/meraki/api-v1/#!cycle-device-switch-ports

 

like : ports = ['1', '2-5'] or simply ports = ['1'] while you are probably passing a string from getDeviceSwitchPorts ( portId = "1" ) 

 

There are  many ways to fix it.  

 

portlist = []

portlist.append(port['portId'])

port_Cycle = dashboard.switch.cycleDeviceSwitchPorts(device['serial'], portlist)

AhmedJawad
Getting noticed

Thank you, that worked! 

RaphaelL
Kind of a big deal
Kind of a big deal

Excellent ! Glad we were able to help you !

 

Have a good one

Get notified when there are additional replies to this discussion.