cancel
Showing results for 
Search instead for 
Did you mean: 

Powershell Generate DPSK though API, but respond 400 error

is_trouser
New Contributor III

I wrote a Powershell script to generate DPSK for users, it works well on query Wlan, Zone, UserRole and other APIs..

But, when I want to generate a DPSK, it responded 400 error. I don't know what is the problem.

 

$UrlBase = "https://10.16.1.14:8443/wsg/api/public";
$apiVer = "v9_1"
$Zone_Id = "69e07745-bac7-4e24-9500-3902960e9700"
$Wlan_Id = "22"

$websession (believe me, $websession works well)

$body_gen=[pscustomobject]@{
amount = "1"
userName = "abc"
userRoleId = "e1538f2a-082c-4e19-b9d7-bc78de006967"
vlanId = ""
groupDpsk = "false"
}

$body_gen_JSON=$body_gen | ConvertTo-Json

Invoke-WebRequest -Uri $UrlBase/$apiVer/rkszones/$Zone_Id/wlans/$Wlan_Id/dpsk/batchGenUnbound -Method POST -Body $body_gen_JSON -ContentType 'application/json;charset=UTF-8' -WebSession $websession

1 ACCEPTED SOLUTION

is_trouser
New Contributor III

I think I fixed it after checking API in Postman. The body should be the format as below:

$body_gen=[pscustomobject]@{
amount = 1
userName = "abc"
userRoleId = "e1538f2a-082c-4e19-b9d7-bc78de006967"
groupDpsk = $false
}

If you don't need to input VlanID, you should totally remove it in the body.

View solution in original post

1 REPLY 1

is_trouser
New Contributor III

I think I fixed it after checking API in Postman. The body should be the format as below:

$body_gen=[pscustomobject]@{
amount = 1
userName = "abc"
userRoleId = "e1538f2a-082c-4e19-b9d7-bc78de006967"
groupDpsk = $false
}

If you don't need to input VlanID, you should totally remove it in the body.