Quantcast
Channel: All Developer posts
Viewing all articles
Browse latest Browse all 48544

500 Internal Server Error encountered when importing PBIX file using PowerShell script

$
0
0

I created below PowerShell script to import PBIX file to workspace:

 

$LF = "`r`n"
$boundary = "----------abcdefghijklmn"
$uri = "https://api.powerbi.cn/v1.0/collections/stanley-test/workspaces/10b69fc3-46fa-464b-9483-41b77b426bb8/imports?datasetDisplayName=Sales"
$CODEPAGE = "iso-8859-1"

$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authorization", "AppKey <accesskey>
$FileContent = [System.IO.File]::ReadAllBytes("D:\temp\RetailAnalysisSamplePBIX.pbix");
$enc = [System.Text.Encoding]::GetEncoding($CODEPAGE)
$fileEnc = $enc.GetString($FileContent)

$body = ("--$boundary$LF",
            "Content-Disposition: form-data; name=`"filename`"; filename=`"RetailAnalysisSamplePBIX.pbix`"$LF",
            "Content-Type: application/octet–stream$LF",
            $fileEnc,
            $LF,
            "--$boundary--",
            $LF) -join $LF;

Invoke-RestMethod -ContentType "multipart/form-data" -Method POST -Uri $uri -Body $body -Headers $headers

 

But when I ran this script it failed with the error "HTTP/1.1 500 Internal Server Error", I'm sure the URL/access key/pbix file path are right but it doesn't work.

 

Can someone help to figure it out? Any answer is greatly appreciated.

 

P.S. PowerShell response:

Invoke-RestMethod : {"Message":""}
At C:\Users\weihuan\Desktop\stanleytest.ps1:20 char:1
+ Invoke-RestMethod -ContentType "multipart/form-data" -Method POST -Ur ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (Method: POST, R...rt/form-data
}:HttpRequestMessage) [Invoke-RestMethod], HttpResponseException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand


Viewing all articles
Browse latest Browse all 48544

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>