Join the FabCon + SQLCon recap series. Up next: Power BI, Real-Time Intelligence, IQ and AI, and Data Factory take center stage. All sessions are available on-demand after the live show. Register now
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.
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)
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.
Check out the April 2026 Power BI update to learn about new features.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 1 | |
| 1 | |
| 1 |