02-20-2020 02:58 AM
Hello my Meraki friends,
This is probably a noob question. I am trying to programmatically edit a VLAN by using the rest API with Python, however I ran into some troubles.
While sending the following json using using requests.put: https://nxxx.meraki.com/api/v0/devices/XXXX-XXXX-XXXX/switchPorts/[portnumber]
Name Value Type
| 'accessPolicyNumber' | None | NoneType | |
| 'allowedVlans' | 'all' | str | |
| 'enabled' | True | bool | |
| 'isolationEnabled' | False | bool | |
| 'linkNegotiation' | 'Auto negotiate' | str | |
| 'macWhitelist' | None | NoneType | |
| 'name' | None | NoneType | |
| 'number' | 10 | int | |
| 'poeEnabled' | True | bool | |
| 'portScheduleId' | None | NoneType | |
| 'rstpEnabled' | True | bool | |
| 'stickyMacWhitelist' | None | NoneType | |
| 'stickyMacWhitelistLimit' | 0 | int | |
| 'stpGuard' | 'disabled' | str | |
| 'tags' | None | NoneType | |
| 'type' | 'trunk' | str | |
| 'udld' | 'Alert only' | str | |
| 'vlan' | 2 | int | |
| 'voiceVlan' | None | NoneType | |
| __len__ | 19 | int |
I get the following response:
'errors': ['Cannot set whitelist on a trunk port', 'Invalid MAC whitelist. To disable MAC whitelist, set accessPolicyNumber to null.']
If you take a look at the first entry of the table above, 'accessPolicyNumber' is indeed filled with a NoneType thing, which is the python equivalent to a null character (right?). Setting 'stickyMacWhitelistLimit' to None is also not an option, since it has to be an integer, while strangely enough if i use get, 'stickyMacWhitelistLimit' is filled with a null character. (which was my motivation to put 0 there in the first place, leading to this).
API command documentation I used is this.
Thanks for your time!
Solved! Go to Solution.
02-20-2020 06:19 AM
None is null, yes.
That looks like you're trying to use Update Device Switch Port?
What happens when you leave the items with value None out? I ran into this with... I forget the call... a while ago. It may have been this one. The GET request returns None options that'll make it unhappy if you include them with a PUT.
02-20-2020 06:19 AM
None is null, yes.
That looks like you're trying to use Update Device Switch Port?
What happens when you leave the items with value None out? I ran into this with... I forget the call... a while ago. It may have been this one. The GET request returns None options that'll make it unhappy if you include them with a PUT.
02-20-2020 06:55 AM
When I leave them out it works!
From my understanding I'd had to send the entire thing. So what I tried to do is do a get request on the port, alter the JSON response to the VLAN I want, and send the edited response back. Seems I can send any amount of key value pairs I want.
Although, it also seems that sending a wholly filled JSON thing with all the values does make the system go places.
02-20-2020 07:08 AM
Finally got a chance to dig in my scripts, and it was this call.
This is probably ugly as heck, but my apparent solution from October:
for port in switchportsList:
switchNum = port['number']
empties = []
for key, value in port.items():
if value == None:
empties.append(key)
for item in empties:
try:
port.pop(item)
except:
print(f"Couldn't pop {item}")
putSwitchport(arg_apikey, arg_serial, port, switchNum, shard)
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