Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

New Member

Trigger dataset refresh programmatically



We are trying to refresh a PowerBI dataset from a background service that runs without a signed-in user.


We have registered a PowerBI App in the Azure portal and assign it with the Tenant.ReadWrite.All Application permission.

In PowerBI we have added the app as the Service Principal for the workspace and enabled all the Admin API settings in the admin page.


The following C# code is throwing a throw 403 Forbidden error. Note that we are using the Microsoft Authentication lib for .NET (MSAL.NET) to generate an access token and the Microsoft.PowerBI.Api lib to interact with the PowerBI API.



                IConfidentialClientApplication confidentialClientApplication = ConfidentialClientApplicationBuilder




                    .WithAuthority(AzureCloudInstance.AzurePublic, tenantId)



                AuthenticationResult authResult = await confidentialClientApplication.AcquireTokenForClient(

                    new string[] {}).ExecuteAsync();


                TokenCredentials tokenCredentials = new(authResult.AccessToken, "Bearer");          

                PowerBIClient pbClient = new(tokenCredentials);


                await pbClient.Datasets.RefreshDatasetAsync(datasetId); // throw 403 - Forbidden


What are we missing?

Super User
Super User

Hi @erandavid ,


Does this blog post help you? 🙂


Let me know! 🙂



Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Thanks Tom for your reply.

It didn't help but I made some progress - I manged to refresh the dataset by creating a token via the UsernamePasswordCredential class and enabling the "Allow public client flows" for the registerd app in the Azure portal.

This is still not good enough since this solution require to provide the username and password of an actual user...
What I would like is to use the app secret instead to create a token (like this: var tokenCredential = new ClientSecretCredential(tenantId, clientId, secret);) , but when I do that I get the 403 Forbidden error.

Helpful resources

PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors