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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register 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
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.