cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Regular Visitor

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.

15 REPLIES 15
Highlighted
Super User V
Super User V

Re: Power BI Export to file Error

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

Highlighted
Regular Visitor

Re: Power BI Export to file Error

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

Highlighted
Super User V
Super User V

Re: Power BI Export to file Error

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

Highlighted
Regular Visitor

Re: Power BI Export to file Error

The export job never finishes.

It never hits the polling function.

The await on the export never comes back.

It should return in a second, max, because the report I'm exporting says only "Test"

 

Is there some hidden setting or framework version I need to set my project to?

I'm copying the documentation code and it is not working.

Highlighted
Super User V
Super User V

Re: Power BI Export to file Error

Doesn't look like the sample code to me.  I think you are putting one "await"  on top of another one?

Highlighted
Regular Visitor

Re: Power BI Export to file Error

/////// Export sample ///////
        public async Task<string> PostExportRequest(
            Guid reportId,
            Guid groupId,
            FileFormat format)
        {
            var client = GetPowerBiClient(); // new Power BI client instance
            var pages = client.Reports.GetPages(groupId, reportId);
            var powerBIReportExportConfiguration = new PowerBIReportExportConfiguration
            {
                Settings = new ExportReportSettings
                {
                    Locale = "en-us",
                },
            };
            var exportRequest = new ExportReportRequest
            {
                Format = format,
                PowerBIReportConfiguration = powerBIReportExportConfiguration,
            };
            Export export = null;
            try
            {
                export = await client.Reports.ExportToFileInGroupAsync(groupId, reportId, exportRequest); // this never returns
            }
            catch (Exception ex)
            {

            }

            // Save the export ID, you'll need it for polling and getting the exported file
            return export.Id;
        }

 

Here's my full function. 
Do I have a double await?

Highlighted
Super User V
Super User V

Re: Power BI Export to file Error

You define the pages but then do not specify them in the request.

 

(You also use Export export instead of var export but I guess that doesn't matter)

Highlighted
Regular Visitor

Re: Power BI Export to file Error

I deleted the line with 'pages' since yes, I'm not using them.

If I don't specify pages, then it'll export the whole report, right?

 

 

Highlighted
Super User V
Super User V

Re: Power BI Export to file Error

That would make too much sense.  So better test with specifying the pages , just in case...

Helpful resources

Announcements

August Community Highlights

Check out a full recap of the month!

August 2020 CYST Challenge

Check out the winners of the recent 'Can You Solve These?' community challenge!

Experience what’s next for Power BI

Join us for an in-depth look at the new Power BI features and capabilities at the free Microsoft Business Applications Launch Event.

Top Kudoed Authors