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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
erandavid
New Member

Trigger dataset refresh programmatically

Hi,

 

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

                    .Create(clientId)

                    .WithClientSecret(secret)

                    .WithTenantId(tenantId)

                    .WithAuthority(AzureCloudInstance.AzurePublic, tenantId)

                    .Build();

 

                AuthenticationResult authResult = await confidentialClientApplication.AcquireTokenForClient(

                    new string[] {https://analysis.windows.net/powerbi/api/.default}).ExecuteAsync();

 

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

                PowerBIClient pbClient = new(tokenCredentials);

 

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

 

What are we missing?

2 REPLIES 2
tackytechtom
Most Valuable Professional
Most Valuable Professional

Hi @erandavid ,

 

Does this blog post help you? 🙂

https://www.tackytech.blog/how-to-refresh-power-bi-datasets-tables-and-partitions-with-azure-functio...

 

Let me know! 🙂

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

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

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

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.