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

Join the FabCon + SQLCon recap series. Up next: Power BI, Real-Time Intelligence, IQ and AI, and Data Factory take center stage. All sessions are available on-demand after the live show. Register now

Reply
Anonymous
Not applicable

Getting error when calling Power BI Embed Report Export To PDF API

We are using Power BI c# SDK to export Power BI report in PDF.
We setup app registration in Azure Active Directory and assigned the required permissions. We Have power-bi-embedded A4 Plan
Some time pdf is generated and some time its not.
When its not generated, following error is thrown:
"Operation returned an invalid status code 'Forbidden'".


Code

var tenantSpecificURL = this.PowerBIConfig.AuthorityUrl.Replace("common", this.PowerBIConfig.TenantId, StringComparison.InvariantCultureIgnoreCase);
var authenticationContext = new AuthenticationContext(tenantSpecificURL);
var credential = new Microsoft.IdentityModel.Clients.ActiveDirectory.ClientCredential(this.PowerBIConfig.ApplicationId, this.PowerBIConfig.ApplicationSecret);
var authenticationResult = await authenticationContext.AcquireTokenAsync(this.PowerBIConfig.ResourceUrl, credential).ConfigureAwait(false);

var tokenCredentials = new TokenCredentials(authenticationResult.AccessToken, "Bearer");
PowerBIClient pbiClient = new PowerBIClient(new Uri(this.PowerBIConfig.ApiUrl), tokenCredentials);
Export export = pbiClient.Reports.ExportToFileInGroup(new Guid(this.PowerBIConfig.WorkspaceId), new Guid(reportID), exportRequest);
string exportId = export.Id;
do
{
export = pbiClient.Reports.GetExportToFileStatusInGroup(new Guid(this.PowerBIConfig.WorkspaceId), new Guid(reportID), exportId);
Console.WriteLine(" - Export status: " + export.PercentComplete.ToString() + "% complete");
}
while (export.Status != ExportState.Succeeded && export.Status != ExportState.Failed);

if (export.Status == ExportState.Failed)
{
Console.WriteLine("Export failed!");
}Capture.PNG

4 REPLIES 4
Anonymous
Not applicable

@AmosHersch  responce error massage

This looks like the exception when the error is returned, what I meant is the Http response message itself, it has headers and body. Maybe you can capture using Fiddler or other tool. Without the response message I can't help much

Anonymous
Not applicable


Operation returned an invalid status code 'Forbidden'||   at *** at Microsoft.Extensions.Internal.ObjectMethodExecutorAwaitable.Awaiter.GetResult()\r\n   at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.TaskOfActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)\r\n   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Logged|12_1(ControllerActionInvoker invoker)\r\n   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)\r\n   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)\r\n   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)\r\n   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)\r\n   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)\r\n   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)\r\n   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)\r\n   at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)\r\n   at *** in ***

AmosHersch
Microsoft Employee
Microsoft Employee

Hi @Anonymous ,

Do you mean that the call to the "Export to File" API returns Forbidden?

Did you check to see if the response body has additional information for the reason of the Forbidden status?

If the response body is empty or doesn't help with understanding the issue you can reply here with the request ID from the response headers and I might be able to find the reason.

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

FabCon and SQLCon Highlights Carousel

FabCon &SQLCon Highlights

Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.