Click here to Skip to main content
15,917,005 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
Hi, I am trying to export a power bi embed report to PDF in a ASP.NET core MVC Application using Power BI REST API.

I followed the microsoft documentation: Export Power BI embedded analytics reports API - Power BI | Microsoft Learn[^]

Below is the method where i am getting the error:
private static async Task<string> PostExportRequest(
            Guid reportId,
            Guid groupId,
            FileFormat format,
            IList<string> pageNames = null, /* Get the page names from the GetPages REST API */
            string urlFilter = null)
            using (var pbiClient = await GetPowerBiClient())

                var powerBIReportExportConfiguration = new PowerBIReportExportConfiguration
                    Settings = new ExportReportSettings
                        Locale = "en-us",
                    // Note that page names differ from the page display names
                    // To get the page names use the GetPages REST API
                    Pages = pageNames?.Select(pn => new ExportReportPage { PageName = pn }).ToList(),
                    //Pages = pages,
                    // ReportLevelFilters collection needs to be instantiated explicitly
                    ReportLevelFilters = !string.IsNullOrEmpty(urlFilter) ? new List<ExportFilter>() { new ExportFilter(urlFilter) } : null


                var exportRequest = new ExportReportRequest
                    Format = format,
                    PowerBIReportConfiguration = powerBIReportExportConfiguration,

                    // The 'Client' object is an instance of the Power BI .NET SDK
                    var export = await pbiClient.Reports.ExportToFileInGroupAsync(groupId, reportId, exportRequest);
                    // Save the export ID, you'll need it for polling and getting the exported file
                    return export.Id;
                catch (HttpOperationException ex)
                    if (ex.Response.StatusCode == HttpStatusCode.NotFound)
                        Console.WriteLine("Report not found.");
                    else if (ex.Response.StatusCode == HttpStatusCode.Forbidden)
                        Console.WriteLine("Access to the report is forbidden.");
                        Console.WriteLine("Error exporting report: " + ex.Response.ReasonPhrase);

                    return null;

I am getting NotFound error while calling the ExportToFileInGroupAsync Power BI REST API in above method.

PageNames are also retrieved correctly from content response which is as below:
      "name":"ReportSectione2c518a1fea59becc220","displayName":"Snowflake Cost Analysis","order":0
      "name":"ReportSection80cedf8a24dcd410907c","displayName":"Snowflake Storage Analysis","order":1

Can anyone help me resolving the error ?

What I have tried:

I verified The report and group ID's are correct.
The PageNames are also retrieved correctly.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900