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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
rsaguiar
New Member

How can I add a member of group workspace using C# PowerBI API

How can I add a member of group workspace using C# PowerBI API?

I trying to add a email member to my workspace using the power bi api for .NET but i'm receiving a message "Operation returned an invalid status code 'Unauthorized'" and i'm using the owner of the workspace.

 

I tryied to use 

Snippet

client.Groups.AddUserAsAdminAsync(grupo.Id, usuario);

and 

Snippet

 client.Groups.UpdateGroupAsAdmin(grupo.Id, grupo);

 and it's the same message in both cases.

 

And i need to give this permission automatically to some users get access to the workspace without using my master user.

 

Regards,

Rafael

2 REPLIES 2
v-jiascu-msft
Microsoft Employee
Microsoft Employee

Hi @rsaguiar,

 

Did you have an authentication step in your codes? We need to get the access token before we call the APIs.

 

Best Regards,

Dale

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

Hi @v-jiascu-msft 

 

Yes, my client object call my method GetPowerBIClient before trying to update my group

 

Snippet

static string GetAccessToken()
        {
            AuthenticationContext authContext = new AuthenticationContext(aadAuthorizationEndpoint);
            var userCredentials = new UserPasswordCredential(pbiUserName, pbiUserPassword);
            return authContext.AcquireTokenAsync(resourceUriPowerBi, aplicationId, userCredentials).Result.AccessToken;
        }
 
        public static PowerBIClient GetPowerBiClient()
        {
            var tokenCredentials = new TokenCredentials(GetAccessToken(), "Bearer");
            pwCliente = new PowerBIClient(new Uri(urlPowerBiRestApiRoot), tokenCredentials);
            return pwCliente;
        }

 

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.