cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
159
Views
1
Helpful
3
Replies

Meraki Adding Network via API

Netmart
Level 1
Level 1

Hello,

I tried the following on Cisco DevNet Sandbox to add a network and received the following error:

 

$ python3 Meraki_Post_Network2.py

Traceback (most recent call last):

  File "Meraki_Post_Network2.py", line 11, in <module>

    requests.post ("/base_url" + org_id +"/organizations",

  File "/home/cisco.local/lib/python3.8/site-packages/requests/api.py", line 115, in post

    return request("post", url, data=data, json=json, **kwargs)

  File "/home/cisco/.local/lib/python3.8/site-packages/requests/api.py", line 59, in request

    return session.request(method=method, url=url, **kwargs)

TypeError: request() got an unexpected keyword argument 'networks

 

 

Meraki_Post_Network2.py

import requests

import meraki

import json



base_url = "https://n583.meraki.com/"

org_id = "CiscoDevNet"

api_key = "37d5d077d3f88d947e94ed4fad5a388f4cb689b2"

network_name = "New Network"

requests.post ("/base_url" + org_id +"/organizations",

    headers = {

        "X-Cisco-Meraki-API-Key": "api_key",

        "Content-Type": "application/json"        

    },

    networks = json.dumps ({ "name": network_name,

                             "type": "wireless switch"

    }))

 

I would appreciate, if someone could please take a look.

 

Thanks,

 

 

1 Accepted Solution

Accepted Solutions

Awesome!

Please mark this as helpful or solution accepted to help others
Connect with me https://bigevilbeard.github.io

View solution in original post

3 Replies 3

Hey @Netmart the error you're encountering is because the requests.post function doesn't have a keyword argument named "networks". Guessing it would be something like this, please test this.

import requests
import json

base_url = "https://n583.meraki.com/"
org_id = "CiscoDevNet"
api_key = "37d5d077d3f88d947e94ed4fad5a388f4cb689b2"
network_name = "New Network"

url = base_url + "api/v1/organizations/" + org_id + "/networks"

headers = {
    "X-Cisco-Meraki-API-Key": api_key,
    "Content-Type": "application/json"
}

data = {
    "name": network_name,
    "type": "wireless switch"
}

response = requests.post(url, headers=headers, json=data)

print(response.text)

 

 

Please mark this as helpful or solution accepted to help others
Connect with me https://bigevilbeard.github.io

Netmart
Level 1
Level 1

Thank you Stuart.

After revising the code as suggested by you I made some progress, but still received the following error:

"{"errors":["The following required parameters are missing: 'productTypes'"]}

There may be other ways to solve this missing parameter; I did it the following way:

 

import requests
import json


org_id = "1423679"

api_key = "37d5d077d3f88d947e94ed4fad5a388f4cb689b2"
network_name = "New Network"
url = base_url + "api/v1/organizations/" + org_id + "/networks"
headers = { "X-Cisco-Meraki-API-Key": api_key,
            "Content-Type": "application/json" }

data = { "name": network_name, "type": "wireless switch""productTypes": ['appliance', 'switch', 'wireless'] }
response = requests.post(url, headers=headers,json=data)
print(response.text.encode('utf8'))    

I appreciate your feedback.

Thanks,

Netmart

Awesome!

Please mark this as helpful or solution accepted to help others
Connect with me https://bigevilbeard.github.io