I think I'm getting closer. Now getting code 400, API Northbound not enabled. (And I figured out body = {'wlan':wlan}
Original Message:
Sent: Mar 29, 2023 09:12 AM
From: AutoCreation
Subject: Change WLAN pre-shared key?
Hi Brannen,
here are the docs I'm referring:
https://developer.arubanetworks.com/aruba-central/reference/apiwlanupdate_wlan_v2
You need to put the wlan object into the body and not the SSID name
wlan = { 'essid':"LTTEST", 'type':"employee", 'wpa_passphrase':'testing123', 'wpa_passphrase_changed':True}body = {'wlan':wlan}apiPath = "/configuration/v2/wlan/IAP_LT_VantagePark/LTTEST" # the api endpoint. from: community.arubanetworks.com discusion post.apiMethod = "PUT"response = central.command( apiMethod=apiMethod, apiPath=apiPath, apiData=body)print(response)
The API params are not used in every API endpoint. These can be used as query parameters, aka what is behind the ? in the URL, for example page number or page size when you query a few hundred APs.
These are not to be confused with the body parameter of the API endpoint.
------------------------------
Thanks,
Bjarne
Original Message:
Sent: Mar 29, 2023 08:13 AM
From: BT20
Subject: Change WLAN pre-shared key?
Hi Bjarne,
Thanks for the code. Would you mind sharing a link to the documentation you were referencing?
I tried to bring your code into mine. I didn't follow where you were bring **kwargs into the function, and then passing them to central.command as apiParams ... where is wlan used?
Note - I commented out my original code, and put the changed code below it.
I tried the code below, and got a 400 "detail LTTEST is not of type 'object':
wlan = { 'essid':"LTTEST", 'type':"employee", 'wpa_passphrase':'testing123', 'wpa_passphrase_changed':True}body = {'wlan':'LTTEST'}# apiPath = "/configuration/full_wlan/IAP_LT_VantagePark/LTTEST" # the api endpoint.apiPath = "/configuration/v2/wlan/IAP_LT_VantagePark/LTTEST" # the api endpoint. from: community.arubanetworks.com discusion post.apiMethod = "PUT"apiParams = cfg_string'''.command is a method of the ArubaCentralBase class. Since we instantiated the class as the objectcentral, the .command method is under the central object.From the sdk doc:This function calls requestURL to make an API call to Aruba Central after gathering parameters required for API call.When an API call fails with HTTP 401 error code, the same API call is retried once after an attempt to refresh access token orcreate new access token is made.'''# This command will make the api call to central. The paramaters were created above.# The api response will be saved into variable, "data"# response = central.command(apiMethod=apiMethod, apiPath=apiPath, apiParams=apiParams)response = central.command(apiMethod=apiMethod, apiPath=apiPath, apiParams=wlan, apiData=body)print(response)
Response:
{'code': 400, 'msg': {'detail': "'LTTEST' is not of type 'object'", 'status': 400, 'title': 'Bad Request', 'type': 'about:blank'}, 'headers': {'Content-Type': 'application/problem+json', 'Content-Length': '119', 'Connection': 'keep-alive', 'X-RateLimit-Limit-day': '1000', 'X-RateLimit-Remaining-day': '998', 'X-RateLimit-Limit-second': '7', 'X-RateLimit-Remaining-second': '6', 'Date': 'Wed, 29 Mar 2023 12:06:01 GMT', 'Access-Control-Allow-Origin': '*', 'Cache-Control': 'no-cache, no-store, must-revalidate, private', 'Pragma': 'no-cache', 'X-Frame-Options': 'SAMEORIGIN', 'X-Request-Start': 't=1680091561.277', 'X-XSS-Protection': '1; mode=block', 'X-Kong-Upstream-Latency': '70', 'X-Kong-Proxy-Latency': '150', 'Via': 'kong/0.14.1'}}
------------------------------
Brannen Taylor
LendingTree
Manager, Network Operations
Original Message:
Sent: Mar 29, 2023 07:33 AM
From: bkohnke
Subject: Change WLAN pre-shared key?
Hi Brannen,
if you are using PyCentral as your connection library, you don't need to loads and dumps JSON because it is based on request and that takes care of that automatically.
Looking at the documentation it should work like this:
from pycentral.base import ArubaCentralBase
def update_psk(central: ArubaCentralBase, group_name: str, wlan_name: str, essid: str, new_psk: str,
wlan_type: str = 'employee', **kwargs) -> dict:
wlan = {
'essid': essid,
'type': wlan_type,
'wpa_passphrase': new_psk,
'wpa_passphrase_changed': True
}
body = {
'wlan': wlan
}
response = central.command(
apiMethod='PUT',
apiPath=f'configuration/v2/wlan/{group_name}/{wlan_name}',
apiParams=kwargs,
apiData=body
)
return response
But I can't test it right now.
------------------------------
Thanks,
Bjarne
Original Message:
Sent: Mar 24, 2023 08:16 AM
From: BT20
Subject: Change WLAN pre-shared key?
Hi Bjarne,
Thanks. I'm able to pull down all the WLAN settings with a GET. I imported them into a python dictionary with json.loads() and changed the value of a key. Then exported the dict back to a string with json.dumps(). I tried to send the string back with a PUT and the SDK but I get a 500 error in swagger and in py code.
I just can't figure out the format the PUT wants - and the documentation doesn't explain it.
There's virtually NO instructions on how to do a PUT to Central API - all the blogs, videos, etc. are using GETs.
------------------------------
Brannen Taylor
LendingTree
Manager, Network Operations
Original Message:
Sent: Mar 24, 2023 05:10 AM
From: AutoCreation
Subject: Change WLAN pre-shared key?
I can not test it right now, but I had some settings where you need to always send the full settings and it is not possible to only send the changed values.
I needed to do this when I want to set the AP hostname. I first download all settings, then adjust the hostname and send it all again.
------------------------------
Thanks,
Bjarne
Original Message:
Sent: Mar 22, 2023 09:25 AM
From: BT20
Subject: Change WLAN pre-shared key?
I'm trying to change a WLAN pre-shared key via Aruba Central API. I'm authenticating with the python SDK and I think I want to change the "wpa_passphrase" through the "Update an existing WLAN" api -
PUT/configuration/full_wlan/{group_name_or_guid_or_serial_number}/{wlan_name}
The get is working in swagger, but not the put. I think I'm putting the wlan_data in wrong - I'm trying:
{
"wpa_passphrase":"testing1234"
}
But I'm getting a 500 Response code.
Should I be trying to change the password through Central? Or should I connect to the IAP and change it locally in the controller AP?
------------------------------
Brannen Taylor
LendingTree
Manager, Network Operations
------------------------------