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

The Power BI Data Visualization World Championships is back! It's time to submit your entry. Live now!

Reply
mmouton
Frequent Visitor

PostImportWithFileInGroup return 'bad request' when uploading a rdl file to a workpsace

Hello,

I'm trying to use powerbi api to upload a report to a workspace. I have build a small C# app that autenticate using service principale.

I'm able to list workspace, get report details of generate a report (.rdl) using a workpace assign to a Fabric capacity.

 

Now I would like to upload a report to a workspace.

 

Here is my sample code.

        public void DeployReport(Guid WorkspaceId, string ReportName, string RdlFilePath)
        {
            using (var stream = new FileStream(RdlFilePath, FileMode.Open, FileAccess.Read))
            {
                var import = pbiClient.Imports.PostImportWithFileInGroup(WorkspaceId, stream, ReportName, ImportConflictHandlerMode.CreateOrOverwrite);
            }
        }

I created a very simple paginated report file 'Dummy.rdl'.

 

<?xml version="1.0" encoding="utf-8"?>
<Report MustUnderstand="df" xmlns="http://schemas.microsoft.com/sqlserver/reporting/2016/01/reportdefinition" xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner" xmlns:df="http://schemas.microsoft.com/sqlserver/reporting/2016/01/reportdefinition/defaultfontfamily" xmlns:am="http://schemas.microsoft.com/sqlserver/reporting/authoringmetadata">
  <rd:ReportUnitType>Mm</rd:ReportUnitType>
  <rd:ReportID>e751893f-4a70-48e0-a89c-c62a7d494aa3</rd:ReportID>
  <am:AuthoringMetadata>
    <am:CreatedBy>
      <am:Name>PBIRB</am:Name>
      <am:Version>15.7.1814.616</am:Version>
    </am:CreatedBy>
    <am:UpdatedBy>
      <am:Name>PBIRB</am:Name>
      <am:Version>15.7.1814.616</am:Version>
    </am:UpdatedBy>
    <am:LastModifiedTimestamp>2025-09-08T08:33:52.0593705Z</am:LastModifiedTimestamp>
  </am:AuthoringMetadata>
  <df:DefaultFontFamily>Segoe UI</df:DefaultFontFamily>
  <AutoRefresh>0</AutoRefresh>
  <ReportSections>
    <ReportSection>
      <Body>
        <ReportItems>
          <Textbox Name="ReportTitle">
            <rd:WatermarkTextbox>Title</rd:WatermarkTextbox>
            <rd:DefaultName>ReportTitle</rd:DefaultName>
            <CanGrow>true</CanGrow>
            <KeepTogether>true</KeepTogether>
            <Paragraphs>
              <Paragraph>
                <TextRuns>
                  <TextRun>
                    <Value>tes mmo</Value>
                    <Style>
                      <FontFamily>Segoe UI Light</FontFamily>
                      <FontSize>28pt</FontSize>
                    </Style>
                  </TextRun>
                </TextRuns>
                <Style />
              </Paragraph>
            </Paragraphs>
            <Top>0mm</Top>
            <Height>12.7mm</Height>
            <Width>139.7mm</Width>
            <Style>
              <Border>
                <Style>None</Style>
              </Border>
              <PaddingLeft>2pt</PaddingLeft>
              <PaddingRight>2pt</PaddingRight>
              <PaddingTop>2pt</PaddingTop>
              <PaddingBottom>2pt</PaddingBottom>
            </Style>
          </Textbox>
        </ReportItems>
        <Height>57.15mm</Height>
        <Style>
          <Border>
            <Style>None</Style>
          </Border>
        </Style>
      </Body>
      <Width>152.4mm</Width>
      <Page>
        <PageFooter>
          <Height>11.43mm</Height>
          <PrintOnFirstPage>true</PrintOnFirstPage>
          <PrintOnLastPage>true</PrintOnLastPage>
          <ReportItems>
            <Textbox Name="ExecutionTime">
              <rd:DefaultName>ExecutionTime</rd:DefaultName>
              <CanGrow>true</CanGrow>
              <KeepTogether>true</KeepTogether>
              <Paragraphs>
                <Paragraph>
                  <TextRuns>
                    <TextRun>
                      <Value>=Globals!ExecutionTime</Value>
                      <Style />
                    </TextRun>
                  </TextRuns>
                  <Style>
                    <TextAlign>Right</TextAlign>
                  </Style>
                </Paragraph>
              </Paragraphs>
              <Top>5.08mm</Top>
              <Left>101.6mm</Left>
              <Height>6.35mm</Height>
              <Width>50.8mm</Width>
              <Style>
                <Border>
                  <Style>None</Style>
                </Border>
                <PaddingLeft>2pt</PaddingLeft>
                <PaddingRight>2pt</PaddingRight>
                <PaddingTop>2pt</PaddingTop>
                <PaddingBottom>2pt</PaddingBottom>
              </Style>
            </Textbox>
          </ReportItems>
          <Style>
            <Border>
              <Style>None</Style>
            </Border>
          </Style>
        </PageFooter>
        <PageHeight>29.7cm</PageHeight>
        <PageWidth>21cm</PageWidth>
        <LeftMargin>2cm</LeftMargin>
        <RightMargin>2cm</RightMargin>
        <TopMargin>2cm</TopMargin>
        <BottomMargin>2cm</BottomMargin>
        <ColumnSpacing>0.13cm</ColumnSpacing>
        <Style />
      </Page>
    </ReportSection>
  </ReportSections>
  <ReportParametersLayout>
    <GridLayoutDefinition>
      <NumberOfColumns>4</NumberOfColumns>
      <NumberOfRows>2</NumberOfRows>
    </GridLayoutDefinition>
  </ReportParametersLayout>
</Report>

 

When a run my code, I have an exception:

Microsoft.Rest.HttpOperationException: Operation returned an invalid status code 'BadRequest'
   at Microsoft.PowerBI.Api.ImportsOperations.UploadFile(Nullable`1 groupId, Stream file, String datasetDisplayName, Nullable`1 nameConflict, Nullable`1 skipReport, Nullable`1 overrideReportLabel, Nullable`1 overrideModelLabel, Nullable`1 subfolderObjectId, Dictionary`2 customHeaders, CancellationToken cancellationToken)
   at Microsoft.PowerBI.Api.ImportsOperations.PostImportFileWithHttpMessage(Nullable`1 groupId, Stream file, String datasetDisplayName, Nullable`1 nameConflict, Nullable`1 skipReport, Nullable`1 overrideReportLabel, Nullable`1 overrideModelLabel, Nullable`1 subfolderObjectId, Dictionary`2 customHeaders, CancellationToken cancellationToken)
   at Microsoft.PowerBI.Api.ImportsOperationsExtensions.PostImportWithFileInGroup(IImportsOperations operations, Guid groupId, Stream fileStream, String datasetDisplayName, Nullable`1 nameConflict, Nullable`1 skipReport, Nullable`1 overrideReportLabel, Nullable`1 overrideModelLabel, Nullable`1 subfolderObjectId)

 

When I look at trafic using fiddler, I see this :

X-PowerBI-Error-Info: RequestedFileIsEncryptedOrCorrupted
X-PowerBI-Error-Details: {"error":{"code":"RequestedFileIsEncryptedOrCorrupted","pbi.error":{"code":"RequestedFileIsEncryptedOrCorrupted","parameters":[],"details":[],"exceptionCulprit":1}}}

I find womeone with the same issue in 2020 ...

REST API - import .rdl file fails using .NET sdk - Microsoft Fabric Community

 

I'm stuck, I went through lots topics on forum but nothing relevant.

Thanks for your help.

 

1 ACCEPTED SOLUTION
mmouton
Frequent Visitor

I finnaly found a worrking solution!

In parameter 'datasetDisplayName' you have to send the name of the report with extension.

 

This is not working:

pbiClient.Imports.PostImportWithFileInGroup(WorkspaceId, stream, "Dummy", ImportConflictHandlerMode.CreateOrOverwrite);

 This is working:

pbiClient.Imports.PostImportWithFileInGroup(WorkspaceId, stream, "Dummy.rdl", ImportConflictHandlerMode.CreateOrOverwrite);

 

This is really confusion because when you list report from the workspace, it returns names without extensions.

View solution in original post

4 REPLIES 4
mmouton
Frequent Visitor

I finnaly found a worrking solution!

In parameter 'datasetDisplayName' you have to send the name of the report with extension.

 

This is not working:

pbiClient.Imports.PostImportWithFileInGroup(WorkspaceId, stream, "Dummy", ImportConflictHandlerMode.CreateOrOverwrite);

 This is working:

pbiClient.Imports.PostImportWithFileInGroup(WorkspaceId, stream, "Dummy.rdl", ImportConflictHandlerMode.CreateOrOverwrite);

 

This is really confusion because when you list report from the workspace, it returns names without extensions.

v-prasare
Community Support
Community Support

If your issue still persists, please consider raising a support ticket for further assistance.
To raise a support ticket for Fabric and Power BI, kindly follow the steps outlined in the following guide:

How to create a Fabric and Power BI Support ticket - Power BI | Microsoft Learn

mmouton
Frequent Visitor

Thank you very much for this answer.

It seems that the body content already macth the form-data format.

 

From feedler, in the headers:

Content-Type: multipart/form-data; boundary="30e5dd2d-915d-470e-bdb9-80c901ce9bcc"

in the body :

--30e5dd2d-915d-470e-bdb9-80c901ce9bcc
Content-Disposition: form-data

<?xml version="1.0" encoding="utf-8"?>
<Report MustUnderstand="df" xmlns="http://schemas.microsoft.com/sqlserver/reporting/2016/01/reportdefinition" xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner" xmlns:df="http://schemas.microsoft.com/sqlserver/reporting/2016/01/reportdefinition/defaultfontfamily" xmlns:am="http://schemas.microsoft.com/sqlserver/reporting/authoringmetadata">
  <rd:ReportUnitType>Mm</rd:ReportUnitType>
  <rd:ReportID>e751893f-4a70-48e0-a89c-c62a7d494aa3</rd:ReportID>
  <am:AuthoringMetadata>
    <am:CreatedBy>
      <am:Name>PBIRB</am:Name>
      <am:Version>15.7.1814.616</am:Version>
    </am:CreatedBy>
    <am:UpdatedBy>
      <am:Name>PBIRB</am:Name>
      <am:Version>15.7.1814.616</am:Version>
    </am:UpdatedBy>
    <am:LastModifiedTimestamp>2025-09-08T08:33:52.0593705Z</am:LastModifiedTimestamp>
  </am:AuthoringMetadata>
  <df:DefaultFontFamily>Segoe UI</df:DefaultFontFamily>
  <AutoRefresh>0</AutoRefresh>
  <ReportSections>
    <ReportSection>
      <Body>
        <ReportItems>
          <Textbox Name="ReportTitle">
            <rd:WatermarkTextbox>Title</rd:WatermarkTextbox>
            <rd:DefaultName>ReportTitle</rd:DefaultName>
            <CanGrow>true</CanGrow>
            <KeepTogether>true</KeepTogether>
            <Paragraphs>
              <Paragraph>
                <TextRuns>
                  <TextRun>
                    <Value>tes mmo</Value>
                    <Style>
                      <FontFamily>Segoe UI Light</FontFamily>
                      <FontSize>28pt</FontSize>
                    </Style>
                  </TextRun>
                </TextRuns>
                <Style />
              </Paragraph>
            </Paragraphs>
            <Top>0mm</Top>
            <Height>12.7mm</Height>
            <Width>139.7mm</Width>
            <Style>
              <Border>
                <Style>None</Style>
              </Border>
              <PaddingLeft>2pt</PaddingLeft>
              <PaddingRight>2pt</PaddingRight>
              <PaddingTop>2pt</PaddingTop>
              <PaddingBottom>2pt</PaddingBottom>
            </Style>
          </Textbox>
        </ReportItems>
        <Height>57.15mm</Height>
        <Style>
          <Border>
            <Style>None</Style>
          </Border>
        </Style>
      </Body>
      <Width>152.4mm</Width>
      <Page>
        <PageFooter>
          <Height>11.43mm</Height>
          <PrintOnFirstPage>true</PrintOnFirstPage>
          <PrintOnLastPage>true</PrintOnLastPage>
          <ReportItems>
            <Textbox Name="ExecutionTime">
              <rd:DefaultName>ExecutionTime</rd:DefaultName>
              <CanGrow>true</CanGrow>
              <KeepTogether>true</KeepTogether>
              <Paragraphs>
                <Paragraph>
                  <TextRuns>
                    <TextRun>
                      <Value>=Globals!ExecutionTime</Value>
                      <Style />
                    </TextRun>
                  </TextRuns>
                  <Style>
                    <TextAlign>Right</TextAlign>
                  </Style>
                </Paragraph>
              </Paragraphs>
              <Top>5.08mm</Top>
              <Left>101.6mm</Left>
              <Height>6.35mm</Height>
              <Width>50.8mm</Width>
              <Style>
                <Border>
                  <Style>None</Style>
                </Border>
                <PaddingLeft>2pt</PaddingLeft>
                <PaddingRight>2pt</PaddingRight>
                <PaddingTop>2pt</PaddingTop>
                <PaddingBottom>2pt</PaddingBottom>
              </Style>
            </Textbox>
          </ReportItems>
          <Style>
            <Border>
              <Style>None</Style>
            </Border>
          </Style>
        </PageFooter>
        <PageHeight>29.7cm</PageHeight>
        <PageWidth>21cm</PageWidth>
        <LeftMargin>2cm</LeftMargin>
        <RightMargin>2cm</RightMargin>
        <TopMargin>2cm</TopMargin>
        <BottomMargin>2cm</BottomMargin>
        <ColumnSpacing>0.13cm</ColumnSpacing>
        <Style />
      </Page>
    </ReportSection>
  </ReportSections>
  <ReportParametersLayout>
    <GridLayoutDefinition>
      <NumberOfColumns>4</NumberOfColumns>
      <NumberOfRows>2</NumberOfRows>
    </GridLayoutDefinition>
  </ReportParametersLayout>
</Report>
--30e5dd2d-915d-470e-bdb9-80c901ce9bcc--

 

But I'm not so sure about the encoding of the file content inside the body. Should it be plain text or binary ...

ibarrau
Super User
Super User

Hi. I'm really no sure about the SDK and C#. I can tell you that in my experience I have go through different errors. I think I had the one you have too. I'm more familiar with python, so no sdk and just writting the whole request. The key to make it work, was using multipart encoder.

import requests
from requests_toolbelt.multipart.encoder import MultipartEncoder
...
url = "https://api.powerbi.com/v1.0/myorg/imports?datasetDisplayName={}".format(datasetDisplayName)
# Dictionary to convert a binary file into form-data format
files = {'value': (None, open(filePath, 'rb'), 'multipart/form-data')}
# The MultipartEncoder is posted as data, don't use files=...!
mp_encoder = MultipartEncoder(fields=files)
# The MultipartEncoder provides the content-type header with the boundary:
headers = {'Content-Type': 'multipart/form-data', "Authorization": "Bearer {}".format(self.token)}
# Run request
requests.post(url, data = mp_encoder, headers=headers)

Have you tried with another file? another rdl or a pbix file?

I hope that helps,


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Happy to help!

LaDataWeb Blog

Helpful resources

Announcements
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.