Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

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

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:

 

 

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.

  • Hi Anonymous ,

     

    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.

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

8 Replies