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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
IanV
Frequent Visitor

Authenticating with C# API V2 against Azure Power BI Workspaces

The new Power BI API under the Microsoft.PowerBI.Api.V2 namespace has some additional functionality that I'd like to leverage, but I can't seem to get it to authenticate for the life of me.

 

Here's an example of how I created a client with V1:

 

 

var apiEndpoint = new Uri("https://api.powerbi.com");
var accessKey = "thisvalueisprovidedbyazure";

var credentials = new TokenCredentials(accessKey, "AppKey");
var clientV1 = new Microsoft.PowerBI.Api.V1.PowerBIClient(apiEndpoint, credentials);

As implied by the fake value, that access key is provided by Azure, as you can see in "Get started with Microsoft Power BI Embedded" article here: https://docs.microsoft.com/en-us/azure/power-bi-embedded/power-bi-embedded-get-started

 

I could then use it with a workspaceId and collectionName (also created in Azure):

var collectionName  = "my-power-bi-collection";
var workspaceId = "00000000-0000-0000-0000-000000000000";

var datasets = await client.Datasets.GetDatasetsAsync(collectionName, workspaceId);

The new API seems to be completely different, however. I tried following the example in this article and the one in the git repository readme file, but it wasn't very clear where some of these values are coming from. They seem geared toward generating an access token via username/password or AD.

 

In the example from github, it's not very clear what some of these values are. For example, what is the ClientId? Why is the AuthorityUrl pointing to "https://login.windows.net/common/oauth2/authorize/"? Is that required for Azure? There is also no mention of workspaces (they seem to have been replaced by groups?)

 

Rather than generating a new token, I tried using the token provided by Azure, and it gives me a 403 FORBIDDEN every time.

 

Does anyone know what is required to get the new API running against Azure Power BI workspaces?

 

1 ACCEPTED SOLUTION
Eric_Zhang
Microsoft Employee
Microsoft Employee

@IanV

The Power BI Embedded workspace collection is being deprecated. The new replacement is Embedding with non-Power BI users (app owns data). The correlated github demo is App Owns Data. See authentication code snippet below.

 

// Create a user password cradentials.
            var credential = new UserPasswordCredential(Username, Password);

            // Authenticate using created credentials
            var authenticationContext = new AuthenticationContext(AuthorityUrl);
            var authenticationResult = await authenticationContext.AcquireTokenAsync(ResourceUrl, ClientId, credential);

            if (authenticationResult == null)
            {
                return View(new EmbedConfig()
                {
                    ErrorMessage = "Authentication Failed."
                });
            }

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

The username and password are of one Power BI Pro account. The client_id is from a registered Azure AD application. See this tutorial.

 

 

View solution in original post

2 REPLIES 2
Eric_Zhang
Microsoft Employee
Microsoft Employee

@IanV

The Power BI Embedded workspace collection is being deprecated. The new replacement is Embedding with non-Power BI users (app owns data). The correlated github demo is App Owns Data. See authentication code snippet below.

 

// Create a user password cradentials.
            var credential = new UserPasswordCredential(Username, Password);

            // Authenticate using created credentials
            var authenticationContext = new AuthenticationContext(AuthorityUrl);
            var authenticationResult = await authenticationContext.AcquireTokenAsync(ResourceUrl, ClientId, credential);

            if (authenticationResult == null)
            {
                return View(new EmbedConfig()
                {
                    ErrorMessage = "Authentication Failed."
                });
            }

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

The username and password are of one Power BI Pro account. The client_id is from a registered Azure AD application. See this tutorial.

 

 

Thanks, I didn't realize that v2 of the API was completely incompatible with the original workspaces. I'll go ahead and give the new way a try.






The Power BI Embedded workspace collection is being deprecated.


That's what I was afraid of. Do you know how long the existing Azure workspaces will be available and how long they'll be accessible vai API v1?

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

February Power BI Update Carousel

Power BI Monthly Update - February 2026

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

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.