web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / PowerBI - REST API - E...
Power Automate
Answered

PowerBI - REST API - Export and then Import in Flow / Power Automate

(0) ShareShare
ReportReport
Posted on by 10

Hi all,

 

I've been banging my head against a brick wall for a while here.

 

I've followed a number of the guides for connecting to PowerBI REST APIs using a custom connector in Flow, and generally have it working well...I'm now succesfully using flows to update parameters, refresh datasets etc.

 

Where I have failed is trying to duplicate a report and dataset, by exporting and importing.

 

I'm using the swagger posted here:

 

https://github.com/microsoft/PowerBI-CSharp/blob/master/sdk/swaggers/swagger.json

 

Flow currently looks like this:

 

Capture.PNG

 

Export is using this:

 

https://docs.microsoft.com/en-us/rest/api/power-bi/reports/exportreportingroup

 

This is succesful and if I put the body of this into a compose, it gives me a zip file, which when downloaded and renamed to .pbix, opens properly. The raw output of that action is:

 

 

{"statusCode":200,"headers":{"Pragma":"no-cache","Transfer-Encoding":"chunked","X-PowerBI-FileName":"Test File.pbix","Strict-Transport-Security":"max-age=31536000; includeSubDomains,max-age=31536000; includeSubDomains","X-Frame-Options":"deny,deny","X-Content-Type-Options":"nosniff,nosniff","RequestId":"[ID]","Access-Control-Expose-Headers":"RequestId","request-redirected":"true","home-cluster-uri":"https://wabi-uk-south-redirect.analysis.windows.net/","Cache-Control":"no-store, must-revalidate, no-cache","Date":"Wed, 29 Apr 2020 03:27:50 GMT","Content-Type":"application/zip","Content-Length":"1839288"},"body":{"$content-type":"application/zip","$content":"UEsDBBQAAAAIAHg[...rest of the content]"}}

 

 

 

I'm then trying to take the body of that and use it with the POST import to group function:

 

https://docs.microsoft.com/en-us/rest/api/power-bi/imports/postimportingroup

 

 

I'm getting this error withn a 400 status code:

 

 

 

{
 "Strict-Transport-Security": "max-age=31536000; includeSubDomains",
 "X-Frame-Options": "deny",
 "X-Content-Type-Options": "nosniff",
 "Access-Control-Expose-Headers": "RequestId",
 "request-redirected": "true",
 "home-cluster-uri": "https://wabi-uk-south-redirect.analysis.windows.net/",
 "RequestId": "d248b4cd-7093-4322-893d-ff971cff3b0f",
 "Date": "Wed, 29 Apr 2020 03:01:46 GMT",
 "Content-Length": "0"
}

 

 

 

If i click the "input" of that action, it shows as:

 

 

 

{"host":{"apiId":"subscriptions/[code removed]/providers/Microsoft.Web/locations/uksouth/runtimes/uk-001/apis/pbi-20connector-[code removed]","connectionReferenceName":"shared_pbi-20connector-[code removed]","operationId":"Imports_PostImportInGroup"},"parameters":{"groupId":"[code removed]","datasetDisplayName":"TestCopy.pbix","importInfo":{"$content-type":"application/zip","$content":"UEsDBBQAAAA[...rest of content]"},"nameConflict":"Abort"}}

 

 

 

Any ideas what I'm doing wrong?  Has anyone succesfully managed to do this that could point me in the right direction?

 

Thanks in advance.

 

Tom.

Categories:
  • rG-tom Profile Picture
    10 on at

    Any ideas at all? Spent some more time looking at this and still getting nowhere!

     

    Thanks,

  • Sophiaaa Profile Picture
    Microsoft Employee on at
  • rG-tom Profile Picture
    10 on at

    Thanks @v-xuding-msft 

     

    These are indeed very helpful, and I've spent a lot of time looking at these to get me as far as I have, but do not help with my specific issue. 

     

    Pretty much the only thing I think I am missing, is what do I need to do with the output of the export step, before injecting it into the import step. It's probably as simple as a compose with some text to define something, but I just cannot figure it out.

     

    Thanks,

     

    Tom.

  • cwebb Profile Picture
    2 on at

    Does your import step work with a pbix file that you haven't just exported, ie one that you've built yourself in Power BI Desktop?

     

    The only other thing I can suggest is to look at this example of how to call the export/import endpoints in PowerShell, which might highlight something that you're doing wrong:

    https://github.com/Azure-Samples/powerbi-powershell/blob/master/copyWorkspace.ps1

     

    HTH,

     

    Chris

  • rG-tom Profile Picture
    10 on at

    Hi @cwebb 

     

    Thanks for looking at this.

     

    I have indeed tried manually too, still failing. From looking at the powershell it looks like the bit that I'm missing is the conversion to the multipart form data:

     

    $packageFileStream = New-Object System.IO.FileStream @($temp_path, [System.IO.FileMode]::Open)
     
    	 $contentDispositionHeaderValue = New-Object System.Net.Http.Headers.ContentDispositionHeaderValue "form-data"
    	 $contentDispositionHeaderValue.Name = "file0"
    	 $contentDispositionHeaderValue.FileName = $file_name
     
     $streamContent = New-Object System.Net.Http.StreamContent $packageFileStream
     $streamContent.Headers.ContentDisposition = $contentDispositionHeaderValue
     
     $content = New-Object System.Net.Http.MultipartFormDataContent
     $content.Add($streamContent)

     

    Any ideas how to do that in Flow?

     

    Thanks,

     

    Tom.

  • rG-tom Profile Picture
    10 on at

    Hey @mwegener 

     

    This looks perfect, thank you. however, my connector is different to yours and isn't working, is there any chance you could share the details of your connector?

     

    Thanks!

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at
  • Verified answer
    Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Hi @Tom-P ,

     

    i found the solution.

    To import a file, request Headers should include Content-Type: multipart/form-data with the file encoded as form data in the request body.

    Flow_PowerBIRestAPI.png

    {
     "$content-type": "multipart/form-data",
     "$multipart": [
     {
     "body": @{body('Export_PBIX')}
     }
     ]
    }

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Automate

#1
11manish Profile Picture

11manish 298 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 289

#3
Henil Profile Picture

Henil 125

Last 30 days Overall leaderboard