Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
BenTheSmaller
Regular Visitor

REST import rdl files

Hi,

 

I'm working on an automated deployment solution in powershell to import to PowerBI using the REST API.

 

I have borrowed the function at this URL and am able to import pbix files without any problems:

 

https://github.com/Microsoft/powerbi-powershell/issues/46

 

function Publish-PowerBIImport {
    param
    (
        [string]$Path,
        [string]$GroupId
    )

    $powerBiBodyTemplate = @'
--{0}
Content-Disposition: form-data; name="fileData"; filename="{1}"
Content-Type: application/x-zip-compressed

{2}
--{0}--

'@

    $fileName = [IO.Path]::GetFileName($Path)
    $boundary = [guid]::NewGuid().ToString()
    $fileBytes = [System.IO.File]::ReadAllBytes($Path)
    $encoding = [System.Text.Encoding]::GetEncoding("iso-8859-1")
    $filebody = $encoding.GetString($fileBytes)
    $body = $powerBiBodyTemplate -f $boundary, $fileName, $encoding.GetString($fileBytes)

    $headers = Get-PowerBIAccessToken

    if ($GroupId) {
        $url = "https://api.powerbi.com/v1.0/myorg/groups/$GroupId/imports?datasetDisplayName=$fileName&nameConflict=CreateOrOverwrite"
    }
    else {
        $url = "https://api.powerbi.com/v1.0/myorg/imports?datasetDisplayName=$fileName&nameConflict=CreateOrOverwrite"
    }

    Invoke-RestMethod -Uri $url -Method Post -Headers $headers -Body $body -ContentType "multipart/form-data; boundary=--$boundary" | Out-Null
    Write-Host "Imported Power BI file $Path"
}

 

However when I feed this function a rdl file, I get the following error:


Invoke-RestMethod :
{"error":{"code":"ImportUnsupportedOptionError","pbi.error":{"code":"ImportUnsupportedOptionError","parameters":{},"details":[],"exceptionCulprit":1}}}
At G:\Visual Studio Projects\PowerShell Scripts\PowerBIDeployment.ps1:34 char:5
+ Invoke-RestMethod -Uri $url -Method Post -Headers $headers -Body ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

 

I have modified the Content-Type header and the encoding to suit the rdl file, as below

 

function Publish-PowerBIImport {
    param
    (
        [string]$Path,
        [string]$GroupId
    )

    $powerBiBodyTemplate = @'
--{0}
Content-Disposition: form-data; name="fileData"; filename="{1}"
Content-Type: text/xml

{2}
--{0}--

'@

    $fileName = [IO.Path]::GetFileName($Path)
    $boundary = [guid]::NewGuid().ToString()
    $fileBytes = [System.IO.File]::ReadAllBytes($Path)
    $encoding = [System.Text.Encoding]::GetEncoding("utf-8")
    $filebody = $encoding.GetString($fileBytes)
    $body = $powerBiBodyTemplate -f $boundary, $fileName, $encoding.GetString($fileBytes)

    $headers = Get-PowerBIAccessToken

    if ($GroupId) {
        $url = "https://api.powerbi.com/v1.0/myorg/groups/$GroupId/imports?datasetDisplayName=$fileName&nameConflict=CreateOrOverwrite"
    }
    else {
        $url = "https://api.powerbi.com/v1.0/myorg/imports?datasetDisplayName=$fileName&nameConflict=CreateOrOverwrite"
    }

    Invoke-RestMethod -Uri $url -Method Post -Headers $headers -Body $body -ContentType "multipart/form-data; boundary=--$boundary" | Out-Null
    Write-Host "Imported Power BI file $Path"
}

The error code suggests rdl import may not yet be supported in this manner, can anyone confirm/deny? Cheers.

2 REPLIES 2
TeresaL
New Member

The problem with your code is the value of the nameConflict parameter:

 

$url = "https://api.powerbi.com/v1.0/myorg/groups/$GroupId/imports?datasetDisplayName=$fileName&nameConflict=CreateOrOverwrite"

For RDL files, the only supported values are Abort or Overwrite.

There is, however, a bug in that we are not returning a helpful error message.  We are looking in to fixing this in a future release.

 

Thanks,

Teresa (MSFT)

Anonymous
Not applicable

Hi All,

 

I am trying to upload  a rdl file to a workspace programatically through Power BI rest API in a .net solution. We are using Power BI .net SDK to acheive this functionality. We are using "PostImportWithFileAsyncInGroup" method to upload the rdl file but getting "Badrequest" error all the time. I  have verified that the capacity has been set "A4" and the Paginated workload is also turned on. It would be really helpful if somebody can shed some light on this issue.

Thanks.

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors