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,
string urlFilter = null)
{
using (var pbiClient = await GetPowerBiClient())
{
var powerBIReportExportConfiguration = new PowerBIReportExportConfiguration
{
Settings = new ExportReportSettings
{
Locale = "en-us",
},
Pages = pageNames?.Select(pn => new ExportReportPage { PageName = pn }).ToList(),
ReportLevelFilters = !string.IsNullOrEmpty(urlFilter) ? new List<ExportFilter>() { new ExportFilter(urlFilter) } : null
};
var exportRequest = new ExportReportRequest
{
Format = format,
PowerBIReportConfiguration = powerBIReportExportConfiguration,
};
try
{
var export = await pbiClient.Reports.ExportToFileInGroupAsync(groupId, reportId, exportRequest);
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.");
}
else
{
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:
{
"@odata.context":"http://wabi-us-north-central-redirect.analysis.windows.net/v1.0/myorg/groups/7e4b125b-8e52-4227-b66d-c272b69defc8/$metadata#pages","value":[
{
"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.