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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Refresh Dataset using API using C#.Net

Hi I was trying to refresh dataset using the Power Bi API and getting 401 Unauthrorized error message.

I was able to get the access tone by passing the parameters --(grant_type : "client_credentials"), (client_secret:XXXXXX)

The application is registred as Native client in Azure portal and granted Read/Write Dataset permission but still i was getting the error message -"The remote server returned an error: (401) Unauthorized."Please let me know if i need to post my code 

Thanks in advance 

 

4 REPLIES 4
v-lid-msft
Community Support
Community Support

Hi @Anonymous ,

 

Sorry for our late in response, We have test with the sameple code and it generated valid access token after we sign in as the users which have access to the dataset: https://docs.microsoft.com/en-us/power-bi/developer/automation/walkthrough-push-data-get-token, Does your Azure Access token generated by a sign in users?


Best regards,

 

 

Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Hi,

I am using the below example in getting access token using the getAccessTokenSilently() method in c# using SSIS packages.

I have not installed any of the Microsoft.IdentityModel.Clients.ActiveDirectory dll's.

If i need to install Microsoft.IdentityModel.Clients.ActiveDirectory, can you please let me know the steps that i need to perform for the Visual studio(Business Intelligence) .

Thanks in Advance 

Example for Power REST API : 

https://community.powerbi.com/t5/Developer/Data-Refresh-by-using-API-Need-Steps/td-p/208928

Hi @Anonymous ,

 

Based on my research, if you want to use the example you shared, you may need install  Azure AD Authentication Library for .NET NuGet package first, it is included in this document: https://docs.microsoft.com/en-us/power-bi/developer/automation/walkthrough-push-data-get-token

 

  1. Install the Azure AD Authentication Library for .NET NuGet package. Your .Net app needs this package to get an authentication security token.

    a. Select Tools > NuGet Package Manager > Package Manager Console.

    b. Enter Install-Package Microsoft.IdentityModel.Clients.ActiveDirectory -Version 2.21.301221612


Best regards,

 

Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Hi , We have a c# code posting the parameters Grant Type, application Secret etc for genarating the access token and this works fine. while using the same token to refresh the data set i was getting 401 UnAuthorized error message.

The application is registered in Azure Portal and using power bi services ,granted api permissioins with Delegated user to Read/Write Dataset

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.