Issue with my python script for change psk for Merkaki ssid

ajsiroin
Comes here often

Issue with my python script for change psk for Merkaki ssid

Trying to use input variables to change our guest network's password and store code in github.

 

CAMPUS_GUEST_PSK = input("Please enter the new Campus-Guest password: ")
 
CAMPUS_GUEST_PSK_VARIABLE = 'CAMPUS_GUEST_PSK'
 
MERAKI_DASHBOARD_API_KEY = input("Please enter the Meraki API key: ")
 
API_KEY_ENVIRONMENT_VARIABLE = 'MERAKI_DASHBOARD_API_KEY'
 
import json
import requests
 
 
# Neqal-Wireless network
# Campus-Guest = SSID 1
 
 
payload = '''{
    "psk": CAMPUS_GUEST_PSK
}'''
 
headers = {
    "Content-Type": "application/json",
    "Accept": "application/json",
    
    "X-Cisco-Meraki-API-Key": MERAKI_DASHBOARD_API_KEY
 
}
 
response = requests.request('Put', url, headers=headers, data = payload)
 
print(response.text.encode('utf8'))
 
 
 
Getting the following when I run the python:
 
b'{"status":400,"error":"Bad request: There was a problem in the JSON you submitted"}'
 
if payload reads like the following:
 
payload = '''{
    "psk": "CAMPUS_GUEST_PSK"
}'''
 
The password changes to CAMPUS_GUEST_PSK instead of what I inputted from the input prompts.
 
The API key is working fine and variable is working fine.

 

6 Replies 6
RaphaelL
Kind of a big deal
Kind of a big deal

Hi, 

 

Your payload is too small.  First do a 'get' ( getNetworkWirelessSsid ) and update the key:value pair of the json content then POST it with updateNetworkWirelessSsid. 


I would also recommend using the Python SDK

 

Examples at : https://developer.cisco.com/meraki/api-v1/#!get-network-wireless-ssid and https://developer.cisco.com/meraki/api-v1/#!update-network-wireless-ssid

ajsiroin
Comes here often

I don't understand "payload is too small"?

 

Why does my other apikey variable work fine?

ajsiroin
Comes here often

Do you have code you can share with me?

RaphaelL
Kind of a big deal
Kind of a big deal

Hi ,

 

I suggest that you look at the links that I posted. 

The payload cannot be simply : 

payload = '''{
    "psk": "CAMPUS_GUEST_PSK"
}'''
 
You are missing every other configuration of the ssid. Name , enabled , authMode and more
 
Also , code examples are provided in the documentation.
ajsiroin
Comes here often

payload = json.dumps({
"psk": CAMPUS_GUEST_PSK
})

 

json.dumps took care of my issue.

 

I can now prompt for password and api key and it will input those variable into the code and change the psk in the network I specify.

ww
Kind of a big deal
Kind of a big deal

use:

 

payload = {
"psk": CAMPUS_GUEST_PSK
}


response = requests.request('PUT', url, headers=headers, data = json.dumps(payload))

 

Get notified when there are additional replies to this discussion.