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.
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
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?
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.
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
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.