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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Anonymous
Not applicable

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 19
Juniorflip
Frequent Visitor

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

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,
};

Anonymous
Not applicable

var fileFormat = FileFormat.PDF
var exportRequest = new ExportReportRequest
{
Format = fileFormat
};

 

here you go. this should work

So I figure out my issue.  I was trying to export as .PNG.  When I did .PDF it works just fine.  Apparently there is a setting that need to be set in the admin portal for .PNG but I can't find it.  Does anyone have any luck enabling .PNG?

Thanks, changing the export file format to .PDF resolved this issue for me as well!

lbendlin
Super User
Super User

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

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

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
Not applicable

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.

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

Anonymous
Not applicable

/////// 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?

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)

Anonymous
Not applicable

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?

 

 

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

Anonymous
Not applicable

In the main application, the C# simply won't move past that line - do not know why. Nothing I do will work to move it past there.

Anonymous
Not applicable

Have you found a resolution for this. Stuk with the same issue!

I found when I tried to export the file as a .PNG or a .CSV then the api call never worked and just hung permanently. But when I changed the export format to .PDF then it worked fine and the code was able to move on to the 'polling for export to finish' logic.

hi, did you use the sample code that is in the  microsoft doc?

if not, can i see you your code .

 

thanks

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.