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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
sachin131
Regular Visitor

Want to add Service Principal as Admin in all the workspaces of organization

Hello Team,

 

I have one requirement where I am trying to assign newly created workspaces to deployment pipelines through rest APIs. Now there is one condition "User/Service principal must be in access list of both pipeline and created workspace" to use that assigning workspace API. 

So now I want to create one background job which will run in every 2 minutes and fetch all the newly created workspaces and assign service principal as admin into those newly created workspace.

 

Please help me with this

3 REPLIES 3
hardikrathod
New Member

Hi @GilbertQ ,

 

I implemented the same by follwing blog provide by you.

But I am facing issue of 401 unauthorized.

my code is as below.

 

string serviceURL = https://api.powerbi.com/v1.0/myorg/admin/groups/{My Group id here}/users;

ModelUserAddingDetails modelUserAddingDetails = new ModelUserAddingDetails(); //Model to add body
modelUserAddingDetails.identifier = {My app id};
modelUserAddingDetails.groupUserAccessRight = "Admin";
modelUserAddingDetails.principalType = "App";

 

var json = new JavaScriptSerializer().Serialize(modelUserAddingDetails);
HttpRequestMessage httpRequestMessage = new HttpRequestMessage()
{
Method = HttpMethod.Post,
RequestUri = new Uri(serviceURL),
Content = new StringContent(json, Encoding.UTF8, "application/json"),
};
httpRequestMessage.Headers.Add("Accept","application/json");
httpRequestMessage.Headers.Add("ContentType",""application/json"");

response = client.SendAsync(httpRequestMessage).Result;

 

 

Response: StatusCode: 401, ReasonPhrase: 'Unauthorized', Version: 1.1

 

I am not able to understand where am I doing mistake?

Hi @hardikrathod 

 

Could you use the Try it button on this link: Admin - Groups GetGroupAsAdmin - REST API (Power BI Power BI REST APIs) | Microsoft Learn

 

if that works then it is something to do with your script.

If it does not work and says unauthorized, then you need to check that the permissions have been setup correctly for the Service Principal and it has been added to the relevant AAD Security Group.





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

Proud to be a Super User!







Power BI Blog

GilbertQ
Super User
Super User

Hi @sachin131 

 

You can use the following Power BI REST API to add the Service Principal to the App Workspace (Group)

Groups - Add Group User - REST API (Power BI Power BI REST APIs) | Microsoft Docs





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

Proud to be a Super User!







Power BI Blog

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors
Top Kudoed Authors