Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago

Power BI Export to file Error

We are using the latest version of the API (V3)
I have copied the code examples from here - 

https://docs.microsoft.com/en-us/power-bi/developer/embedded/export-to

in my 'PostExportRequest' function I have tried the following - 

var Client = GetPowerBiClient();
var export = Client.Reports.ExportToFileAsync(reportId, exportRequest); 
export.Wait(); 
var exportResult = export.Result;


On the wait, I get a 'Forbidden' error

The user accessing this is acting as a Service Principal and is set to have full admin rights on the PowerBI settings.

 

on this -

var Client = GetPowerBiClient(); var export = Await Client.Reports.ExportToFileAsync(reportId, exportRequest);


This never completes and seems to run forever.

19 Replies

  • Aren't you supposed to check periodically for the rendering process to complete? It's asynchronous, so Wait() seems to be counter intuitive.

    • Anonymous's avatar
      Anonymous
      Not applicable
      var Client = GetPowerBiClient(); 
      var export = Await Client.Reports.ExportToFileAsync(reportId, exportRequest);

       

      lbendlin If I leave the code as this, it never finishes processing. As a dev, to test, I'm willing to wait maybe 5 minutes, but I left it going for an hour withno results

      • lbendlin's avatar
        lbendlin
        Super User

        According to the documentation:

         

        https://docs.microsoft.com/en-us/power-bi/developer/embedded/export-to

         

        Quote: "The API is asynchronous. When the exportToFile API is called, it triggers an export job. After triggering an export job, use polling to track the job, until it's complete.

        During polling, the API returns a number that represents the amount of work completed. The work in each export job is calculated based on the number of pages the report has. All pages have the same weight. If for example you're exporting a report with 10 pages, and the polling returns 70, it means that the API has processed seven out of the 10 pages in the export job.

        When the export is complete, the polling API call returns a Power BI URL for getting the file. The URL will be available for 24 hours."

  • Anonymous's avatar
    Anonymous
    Not applicable

    I am stuck in the same spot as well.  The error I am getting is that the pageName is not declared

     

    Pages = pageNames?.Select(pn => new ExportReportPage(pageName = pn)).ToList(),

     

    does anyone know what pageName is supposed to be declared?

    • Anonymous's avatar
      Anonymous
      Not applicable

      Good news:
      If you don't specify the pages there, it'll print the full report every time.

      It also seems to default to "en-us" as the locale if you don't specify.

      It actually needs very minimal configuration

      Just giving it a format in the export request is enough for the configto be done and complete.

      • Anonymous's avatar
        Anonymous
        Not applicable

        can you provide a code snippet of this part so that I can see?

         

        var powerBIReportExportConfiguration = new PowerBIReportExportConfiguration
        {
        Settings = new ExportReportSettings
        {
        Locale = "en-us",
        },

        Pages = pageNames?.Select(pn => new ExportReportPage(pageName = pn.ToString())).ToList(),

        };
        var exportRequest = new ExportReportRequest
        {
        Format = fileFormat,
        PowerBIReportConfiguration = powerBIReportExportConfiguration,
        };