I am currently working on a function to modify MX ports for our retail deployments to make everything quicker and easier for me. I primarily am using the Meraki Python module, but for this particular API endpoint, that is not yet supported from what I can see by the Python module, so I am using requests to make the call directly. Now I have done this for a couple other functions with no major issue so far... but for some reason I am getting 400 from the response when I am using multiple parameters. When I use a single parameter it goes through absolutely fine. I am not a developer by trade so I do not have a lot of experience in this sort of thing, but using the Curl to Python converter here It converts the sample request from the documentation to the Python equivalent request of: headers = {
'X-Cisco-Meraki-API-Key': '<key>',
'Content-Type': 'application/json',
}
data = '{"enabled":true,"type":"access","dropUntaggedTraffic":false,"vlan":3,"accessPolicy":"open"}'
response = requests.put('<a href="https://api.meraki.com/api/v0/networks/%7BnetworkId%7D/appliancePorts/%7BappliancePortId%7D" target="_blank">https://api.meraki.com/api/v0/networks/%7BnetworkId%7D/appliancePorts/%7BappliancePortId%7D</a>', headers=headers, data=data) Using .format() on the URL string I replace the garbage for the network id and the MX port number with correct values. I modified the parameters to use the ones I care about. However, it seems if there is more than one parameter it is a bad request, but a single parameter is successful. You can see this from the unused ports (5-12) which only have the enabled:false parameter to disable them. Not sure what I am doing wrong, as I am doing everything the same as I have done before for other endpoints as far as the data being passed is concerned... what am I missing? def update_mx_ports(HEADERS, NID):
r = requests.get(
"<a href="https://api.meraki.com/api/v0/networks/{}/appliancePorts".format(NID" target="_blank">https://api.meraki.com/api/v0/networks/{}/appliancePorts".format(NID</a>),
headers=HEADERS,
)
if r.status_code == 200:
print("Successfully retrieved MX LAN port info...")
r = json.loads(r.text)
for port in r:
for k, v in port.items():
if k == "number" and v == 3:
print("Entering Port 3")
data = '{"enabled":true,"type":"trunk","dropUntaggedTraffic":true,"allowedVlans":252,900,999}'
response = requests.put(
"<a href="https://api.meraki.com/api/v0/networks/{}/appliancePorts/{}".format" target="_blank">https://api.meraki.com/api/v0/networks/{}/appliancePorts/{}".format</a>(
NID, v
),
headers=HEADERS,
data=data,
)
print(response)
elif k == "number" and v == 4:
print("Entering Port 4")
data = '{"enabled":true,"type":"trunk","dropUntaggedTraffic":true,"allowedVlans":252,900,999}'
response = requests.put(
"<a href="https://api.meraki.com/api/v0/networks/{}/appliancePorts/{}".format" target="_blank">https://api.meraki.com/api/v0/networks/{}/appliancePorts/{}".format</a>(
NID, v
),
headers=HEADERS,
data=data,
)
print(response)
elif k == "number" and v > 4:
print("Entering Port", v)
data = '{"enabled":false}'
response = requests.put(
"<a href="https://api.meraki.com/api/v0/networks/{}/appliancePorts/{}".format" target="_blank">https://api.meraki.com/api/v0/networks/{}/appliancePorts/{}".format</a>(
NID, v
),
headers=HEADERS,
data=data,
)
print(response)
... View more