- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
400 Bad request: While creating a new network
Hi,
The following is the python code I am using to create a new network. Tried so many times with little changes each time to figure out the problem but no luck.Here are the error codes and response I am getting:
error code : 400 bad request
response.text : '{"errors":["Invalid type"]}'
response.raise_for_status : 400 Client Error: Bad Request for url : https://n57.meraki.com/api/v0/organizations/XXX/networks
Help me in understanding the problem ! what exactly is wrong with the code/data format.
Thanks
import requests import json def isjson(data): try: json_object = json.loads(data) except ValueError: return False return True url = 'https://api.meraki.com/api/v0/organizations/XXXXX/networks' #payload = " {\n \"name\": \"office\",\n \"timeZone\": \"CET\",\n \"tags\": \"test\",\n \"type\": \"wireless\"\n }" headers = { 'X-Cisco-Meraki-API-Key': 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', 'Content-Type': 'application/json' } payload={ 'name':'office', 'timeZone':'CET', 'tags':'test', 'type':'wireless' } parsed=json.dumps(payload) if isjson(parsed): response = requests.post(url,headers=headers,data=parsed) print(response.text)
Solved! Go to solution.
- Labels:
-
Dashboard API
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks to All of you !
Its executed, and network created.
There was a mistake in the argument type:'combined', Changed it to appliance, its working now. Apologies that I have given wireless in the type, which invited confusion in troubleshooting.
Thanks for your support !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm just starting to learn Python, so I apologize if I'm not much help here.
That being said:
Error 400 = Bad Request- You did something wrong, e.g. a malformed request or missing parameter.
Just in case, I would change your POST command from n57 to just API, in case your shard in not accurate.
The error message you show is showing n57 but the python script is showing API. Any link between the two somewhere else we are not seeing?
Also you have # in front of PAYLOAD. Assuming that is supposed to be there?
Here are some things I found that might assist you:
https://create.meraki.io/build/meraki-python-library-installation-guide/
https://github.com/meraki/automation-scripts
@MacuserJim <---- Jim here has a screenshot on another thread which appears to show how to create a new network.
Good luck and let me know how it goes, would love to learn from this. ^_^
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks Nolan for your time and the links you posted.
Tried importing the Meraki package as @MacuserJim did, and still getting the same error (bad request- invalid type).
@NolanHerring I tried giving payload (string / json) directly to requests.post() as a data and ended up with the same error, Then I commented it to supply parsed json dictionary (jason=json.dumps(payload)).
@NolanHerring About url: It is redirected to n57 from api.meraki,com. I think that is usual.
Error remains even after using meraki package. Any help would be great.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Right off the hop I can see that you're not specifying a valid timezone. For CET you'd want to be specifying something like "Europe/Berlin" or Europe/Paris".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Changed time zone to specific one like you said, still the same error. Installed postman an hour ago and sent the POST request it is also giving the same error.
>>> response.text
'{"errors":["Invalid type"]}'
>>> response
<Response [400]>
>>>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Take a quick look at the documentation:
https://dashboard.meraki.com/api_docs#create-a-network
You'll first need to send a query to get your Organisation ID. Check out the curl example as well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@Vishnu wrote:
'{"errors":["Invalid type"]}'
I'm guessing this is the problem, but wireless should be a valid type. I'm kinda confused here 😞
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Well... @Vishnu your code works fine for me. Now I'm even more confused why it doesn't work for you.
It even took the CET for the timezone...
Does the API key you're using have the correct permissions to create a network in the Org you're working with?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Just for the hell of it, try deleting:
type':'wireless'
And then manually type it back in.
I wonder if you have a strange non-printable character in that string.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Is there any chance this network already exists, potentially as another type already?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks to All of you !
Its executed, and network created.
There was a mistake in the argument type:'combined', Changed it to appliance, its working now. Apologies that I have given wireless in the type, which invited confusion in troubleshooting.
Thanks for your support !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Meraki wrote:
The type of the new network. Valid types are 'wireless' (for MR), 'switch' (for MS), 'appliance' (for MX, Z-Series), 'phone' (for MC), or a space-separated list of those for a combined network.
https://api.meraki.com/api_docs#create-a-network
