cancel
Showing results for 
Search instead for 
Did you mean: 

Upload DPSK file via API met error

is_trouser
New Contributor III

It shows like below:

{
    "message""DPSK upload file fail, an unexpected error occurred.",
    "errorCode"0,
    "errorType""Internal server error"
}
 
The DPSK file is the one I exported from web console. I can import it to Zone on the web console. I don't know why it didn't work via API?
1 ACCEPTED SOLUTION

Parik_MN
RUCKUS Team Member

Hello @is_trouser

 

Follow the steps mentioned below in the screen shot, this is an example of uploading CSV using POSTMAN:

Use the following URL to POST: https://<vSZ_IP>:8443/wsg/api/public/v11_0/rkszones/<Zone_ID>/wlans/<WLAN_ID>/dpsk/upload

 

Parik_MN_1-1660664761603.png

 

1. Navigate and click on BODY tab.

2. Choose option "form-data".

3.  Under Key Column, click on file drop down menu.

4. Choose option "file" from drop down menu.

5. Under Value column, click on "select-files" and choose the CSV file.

6. Under Key Column, type in "file" as a Key Value.

7. Hit send, if all the CSV data are valid, vSZ should accept the file and create DPSKs.

 

Regards,

Parik

 

View solution in original post

6 REPLIES 6

Parik_MN
RUCKUS Team Member

Hello @is_trouser

 

Follow the steps mentioned below in the screen shot, this is an example of uploading CSV using POSTMAN:

Use the following URL to POST: https://<vSZ_IP>:8443/wsg/api/public/v11_0/rkszones/<Zone_ID>/wlans/<WLAN_ID>/dpsk/upload

 

Parik_MN_1-1660664761603.png

 

1. Navigate and click on BODY tab.

2. Choose option "form-data".

3.  Under Key Column, click on file drop down menu.

4. Choose option "file" from drop down menu.

5. Under Value column, click on "select-files" and choose the CSV file.

6. Under Key Column, type in "file" as a Key Value.

7. Hit send, if all the CSV data are valid, vSZ should accept the file and create DPSKs.

 

Regards,

Parik

 

is_trouser
New Contributor III

Hi @Parik_MN 

You are right, I missed the 6th step before. Now it works well in Postman.

But actually I want to run it in PowerShell. I have no idea about it. I have never uploaded file via PowerShell. Could you provide a script sample to me? Thanks a lot!

Parik_MN
RUCKUS Team Member

Hello @is_trouser

Sorry to say this, we are not PowerShell experts. From API logic perspective, I would suggest to use content-type as mentioned below in PowerShell and the DPSK CSV file URL should be used to upload the file.

Any assistance from Ruckus end? Please feel free to chime in.

 

Content-Type: multipart/form-data

 

Regards,

Parik

is_trouser
New Contributor III

Hi @Parik_MN  I found the solution and test it successfully. Hopefully, it can help other people who has the same issue.

################# Base Info #################
$UrlBase = "https://ac.contoso.com:8443/wsg/api/public";
$apiVer = "v9_1"
$Zone_Id_1 = "69e07745-bac7-4e24-9500-3902960e9700"
$Wlan_Id_1_Office = "45"

################# Create Login Session #################
#Login and transfer Cookie
$Body = [pscustomobject]@{
username = "DPSK_Mgmt"
password = "XXXXXXXXX"
timeZoneUtcOffset = "+08:00"
}
$json = $Body | ConvertTo-Json
$session = Invoke-WebRequest -Uri $UrlBase/$apiVer/session -Method Post -Body $json -ContentType 'application/json' -SessionVariable websession

$stringCookie = [string]$session.Headers["Set-Cookie"]
$cookie = $stringCookie.substring(0,($stringCookie.length - 21))

$headers = @{}
$headers.Add("Cookie",$cookie)

################# Upload DPSK File #################
$FilePath = 'C:/Users/is_trouser/Downloads/batch_dpsk_sample.csv'

$FileName = Split-Path $FilePath -leaf -resolve

$FileBytes = [System.IO.File]::ReadAllBytes($FilePath)
$FileEnc = [System.Text.Encoding]::GetEncoding('UTF-8').GetString($FileBytes)
$boundary = [System.Guid]::NewGuid().ToString()
$LF = "`r`n"

$bodyLines = (
"--$boundary",
"Content-Disposition: form-data; name=`"file`"; filename=`"$FileName`"",
"Content-Type: application/octet-stream$LF",
$FileEnc,
"--$boundary--$LF"
) -join $LF

Invoke-RestMethod -Uri $UrlBase/$apiVer/rkszones/$Zone_Id_1/wlans/$Wlan_Id_1_Office/dpsk/upload -Method POST -Headers $headers -ContentType "multipart/form-data; boundary=`"$boundary`"" -Body $bodyLines -WebSession $websession

################# Remove Login Session #################
Invoke-WebRequest -Uri $UrlBase/$apiVer/session -Method DELETE -ContentType 'application/json'

 

Notice: CSV file can NOT include any other attributes which is more than sample file and attribute value can NOT be enclosed in quotation marks, otherwise the import will fail with status code 422