Don't miss your chance to take the Fabric Data Engineer (DP-600) exam for FREE! Find out how by watching the DP-600 session on-demand now through April 28th.
Learn moreJoin 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
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!");
}
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
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 ***
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.
Check out the April 2026 Power BI update to learn about new features.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
| User | Count |
|---|---|
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |