Deploy SSID with a Merki /Python request and a file with diffrent network Id’s

Ishai
Here to help

Deploy SSID with a Merki /Python request and a file with diffrent network Id’s

Hello community,

I Need your assistance with a Meraki, Python issue,

I’m not a python specialist and I really wonder if the solution is really that simple with Python.

 

Let’s say I have 100 networks and I want to enable SSID interface Nr. 2 with a specific VLAN Nr. (The WLAN configuration is not the issue here).

 

I want to use the below python script to read through a . txt or .CSV file and execute the command below for every network.

Networkid.txt
N_111111111111111111
N_111111111111111112
N_111111111111111113
N_111111111111111114
N_111111111111111115

 

Read a file with networkids, execute the Python - Request  “URL” with the variable Networkid and go for the  next Networkid.

 

url = "https://api.meraki.com/api/v1/networks/{networkId}/wireless/ssids/{number}"

url = "https://n123.meraki.com/api/v1/networks/networkid/appliance/ssids/2"


******This Script works fine for a single Network****

 

 

 

import meraki
import requests
dashboard = meraki.DashboardAPI()

url = "https://n123.meraki.com/api/v1/networks/N_111111111111111113/appliance/ssids/2"

payload = '''{
        "number": 2,
        "name": "Test_3333",
        "enabled": true,
        "defaultVlanId": 777,
        "authMode": "psk",
        "psk": "xtesty2022",
        "encryptionMode": "wpa",
        "wpaEncryptionMode": "WPA2 only",
        "visible": false

}'''

 

 

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

response = requests.request('PUT', url, headers=headers, data = payload)
print(response.text.encode('utf8'))

 

Thank you in advance

Ishai

4 Replies 4
PhilipDAth
Kind of a big deal
Kind of a big deal

I found this sample script in the Meraki repository that sets a VLAN ID for an SSID, or all networks with a specific tag.

https://github.com/meraki/automation-scripts/blob/master/setssidvlanid.py 

It is so close to what you want you could probably modify it.

 

Otherwise I would use the Meraki python module, and simply loop thorugh the networks and make the change.  You can find the developer documentation here:

https://developer.cisco.com/meraki/api-v1/ 

Most of the APIs have an example of how to do it using the Meraki Python module.

 

Ishai
Here to help

 

Hi Philip

Hi Philip

 

Thank you for your quick response and the suggested solutions,

I need some time to go through this script and try things out (im not the Python specialist yet).

The moment I have some results I’ll let you know,

Kind regards

Ishai

 

Thank you for your quick response and the suggested solutions,

I need some time to go through this script and try things out (im not the Python specialist yet).

The moment I have some results I’ll let you know,

Kind regards

Ishai

Ishai
Here to help

Hi Philip,

Due to time pressure I did not have time to go dip in the above script,

I found another way to do this. It’s a combination of API and Postman.

But I did not give up on the Scripting part, don’t worry.

 

Thanks again

Ishai

PaulF
Meraki Employee
Meraki Employee

Hey,

 

So, I've simplified an existing script I have.

 

It takes a CSV with the following headers:

 

networkId,SSIDName, VLAN

 

 

import meraki
import logging, sys, getopt
import pandas as pd

# Ingests a CSV file with the following headers:
# networkId, SSIDName, VLAN

def main(argv):

    print(meraki.__version__)

    try:
        opts, args = getopt.getopt(argv, 'k:o:')
    except getopt.GetOptError:
        sys.exit(2)

    for opt, arg in opts:
        if opt == '-k':
            arg_apikey = arg
        elif opt == '-o':
            arg_org_id = arg

    if arg_apikey == '' or arg_org_id == '':
        sys.exit(2)

    client = meraki.DashboardAPI(api_key=arg_apikey)

    APData = pd.read_csv("CSV-Networks.csv")

    for index, row in APData.iterrows():

        SSIDInfo = row.to_dict()
        networkID = SSIDInfo["networkId"]
        SSIDName = SSIDInfo["SSIDName"]
        SSIDVLAN = int(SSIDInfo["VLAN"])
        SSIDNPSK = "5656565656"

        try:

            setSSID = client.wireless.updateNetworkWirelessSsid(networkId=networkID,
                                                                number="2",
                                                                enabled=True,
                                                                name=SSIDName,
                                                                encryptionMode="wpa",
                                                                useVlanTagging=True,
                                                                defaultVlanId=SSIDVLAN,
                                                                authMode="psk",
                                                                ipAssignmentMode="Bridge mode",
                                                                psk=SSIDNPSK,
                                                                availableOnAllAps=False,
                                                                availabilityTags=[SSIDName])
        except meraki.APIError as e:
            print(e.message)

if __name__ == '__main__':
    main(sys.argv[1:])

 

 

 

It uses the following python Libraries:

Pandas : For reading multi column CSVs and

Meraki : Makes using the API so much easier

 

and it takes the following arguments:

 

-o yourOrgID

-k yourAPI key

 

I hope that this helps.... 

Get notified when there are additional replies to this discussion.