0

I am working with the Meraki API's to update switch port info. I can add a voiceVlan just fine. The issue is when I try to remove (blank out) an existing voiceVlan via the API.

I am not the first person with this issue: https://community.meraki.com/t5/Developers-APIs/which-parameters-in-an-API-call-are-required/m-p/61890/highlight/false#M1973

One person said it started working when he added: 'Content-Type':'application/json', but I already have that.

I believe I know what is wrong, but I do not know how to get past it.

The voiceVlan field is an integer field. If I feed it any integer it works. The new value is successfully updated.

In my .csv file that I feed to my Python program I am placing 'null'. I called Meraki support and they said they can't trouble shoot 'third party' (i.e., personal) programs, but they said they can update it via cURL using null.

In the PyCharm debugger I see this: enter image description here

Notice how the voiceVlan shows an empty string even though my .csv file has null in that field.

Then, when I convert the dict to json (port_data = ) I see this: enter image description here

voiceVlan is an empty string. That won't work, so that is my problem. 'enabled": true is correct and that is how it is in my .csv file. My issue, which I don't know how to resolve, is how do I get the voiceVlan value to be null instead of an empty string after I convert the dict to json?

The value in port_data for voiceVlan needs to be null, not an empty string.

MarkS
  • 1,455
  • 2
  • 21
  • 36

2 Answers2

1

In python,None -> null. Try to use:

new_dict['voiceVlan'] = None

before

json.dumps(new_dict)
jizhihaoSAMA
  • 12,336
  • 9
  • 27
  • 49
0

I just found a post by @unutbu that fixed my issue:

if new_dict['type'] == 'access':
    new_dict['voiceVlan'] = None if new_dict['voiceVlan'] == 'None' else new_dict['voiceVlan']

Pythonic way to convert the string "None" to a proper None

MarkS
  • 1,455
  • 2
  • 21
  • 36