Attempting to Change PSK of SSID with Meraki API via Powershell - error 400 Bad Request

Solved
joedelapaz
Conversationalist

Attempting to Change PSK of SSID with Meraki API via Powershell - error 400 Bad Request

Hello All,

 

I am trying to change the PSK of my SSID using the API.

However, I am getting this error message.

Any help would be greatly appreciated.

I've pasted the code below.

 

VERBOSE: PUT https://n249.meraki.com/api/v0/networks/xxxxxxxxxxxxxxxxxxxxxxx/ssids/6 with -1-byte payload
Invoke-RestMethod : The remote server returned an error: (400) Bad Request.
At D:\Change_PSK.ps1:37 char:1
+ Invoke-RestMethod -Method Put -Uri $Merakiuri -Headers $header_org -B ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

 

[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12 -bor [System.Net.SecurityProtocolType]::Tls11

$date = Get-Date -format "yyyyMMdd"
#$DateStr = $date.ToString("yyyyMMdd")

Write-Host $date

#Meraki API KEY
$api_key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
#Meraki Network URL
$network_id = "xxxxxxxxxxxxxxxxxxxx"
#Base API URL
$api = @{
    "endpoint" = 'https://api.meraki.com/api/v0'
}
#API URL for SSID PSK Change XXX
$api_put = @{
    "endpoint" = 'https://n249.meraki.com/api/v0'
}

$header_org = @{
    "X-Cisco-Meraki-API-Key" = $api_key
    "Content-Type" = 'application/json'
}
# PSK = New password
$data = @{
    "psk" = 'NewPassword' + $date
}
Write-Host $data
#Convert data to Json format
$jbody = ConvertTo-Json -InputObject $data
#URL Network_ID and SSID number
$api.ssid = "/networks/$network_id/ssids/6"
#Combine base api_put URL and $api.ssid
$Merakiuri = $api_put.endpoint + $api.ssid
Invoke-RestMethod -Method Put -Uri $Merakiuri -Headers $header_org -Body $jbody -Verbose
1 Accepted Solution
BrechtSchamp
Kind of a big deal

That's because the SSID is probably set to open.

 

Try adding these to the code:

$data = @{
    "psk" = 'NewNewPassword' + $date
	"authMode" = 'psk'
	"encryptionMode" = 'wpa'
	"wpaEncryptionMode" = 'WPA2 only' # you could also use 'WPA1 and WPA2'
}

Or set it up via dashboard before running your script the first time:

wpa_setup.PNG

View solution in original post

2 Replies 2
BrechtSchamp
Kind of a big deal

That's because the SSID is probably set to open.

 

Try adding these to the code:

$data = @{
    "psk" = 'NewNewPassword' + $date
	"authMode" = 'psk'
	"encryptionMode" = 'wpa'
	"wpaEncryptionMode" = 'WPA2 only' # you could also use 'WPA1 and WPA2'
}

Or set it up via dashboard before running your script the first time:

wpa_setup.PNG

joedelapaz
Conversationalist

Thank you very much for your response.

It worked like a charm.

The PSK is now updating properly.

Get notified when there are additional replies to this discussion.