Microsoft Fabric Community Conference 2025, March 31 - April 2, Las Vegas, Nevada. Use code FABINSIDER for a $400 discount.
Register nowThe Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.
i am facing error in this line : var profile = pbiClient.Profiles.CreateProfile(createRequest);
public PowerBiTenant OnboardNewTenant(PowerBiTenant tenant)
{
this.SetCallingContext();
var createRequest = new CreateOrUpdateProfileRequest(tenant.Name + " Profile");
var profile = pbiClient.Profiles.CreateProfile(createRequest);
string profileId = profile.Id.ToString();
tenant.ProfileId = profileId;
SetCallingContext(profileId);
// create new app workspace
GroupCreationRequest request = new GroupCreationRequest("AODSK: " + tenant.Name);
Group workspace = pbiClient.Groups.CreateGroup(request);
// assign new workspace to dedicated capacity
if (targetCapacityId != "")
{
pbiClient.Groups.AssignToCapacity(workspace.Id, new AssignToCapacityRequest
{
CapacityId = new Guid(targetCapacityId),
});
}
tenant.WorkspaceId = workspace.Id.ToString();
tenant.WorkspaceUrl = "https://app.powerbi.com/groups/" + workspace.Id.ToString() + "/";
// This code adds service principal as workspace Contributor member
// -- Adding service principal as member is required due to security bug when
// -- creating embed token for paginated report using service princpal profiles
var userServicePrincipal = pbiClient.Groups.GetGroupUsers(workspace.Id).Value[0];
string servicePrincipalObjectId = userServicePrincipal.Identifier;
pbiClient.Groups.AddGroupUser(workspace.Id, new GroupUser
{
Identifier = servicePrincipalObjectId,
PrincipalType = PrincipalType.App,
GroupUserAccessRight = "Contributor"
});
// add user as new workspace admin to make demoing easier
string adminUser = Configuration["DemoSettings:AdminUser"];
if (!string.IsNullOrEmpty(adminUser))
{
pbiClient.Groups.AddGroupUser(workspace.Id, new GroupUser
{
Identifier = adminUser,
PrincipalType = PrincipalType.User,
EmailAddress = adminUser,
GroupUserAccessRight = "Admin"
});
}
// upload sample PBIX file #1
string importName = "Sales";
PublishPBIX(workspace.Id, importName);
Dataset dataset = GetDataset(workspace.Id, importName);
UpdateMashupParametersRequest req =
new UpdateMashupParametersRequest(new List<UpdateMashupParameterDetails>() {
new UpdateMashupParameterDetails { Name = "DatabaseServer", NewValue = tenant.DatabaseServer },
new UpdateMashupParameterDetails { Name = "DatabaseName", NewValue = tenant.DatabaseName }
});
pbiClient.Datasets.UpdateParametersInGroup(workspace.Id, dataset.Id, req);
PatchSqlDatasourceCredentials(workspace.Id, dataset.Id, tenant.DatabaseUserName, tenant.DatabaseUserPassword);
pbiClient.Datasets.RefreshDatasetInGroup(workspace.Id, dataset.Id);
if (targetCapacityId != "")
{
// only import paginated report if workspace has been associated with dedicated capacity
string PaginatedReportName = "Sales Summary";
PublishRDL(workspace, PaginatedReportName, dataset);
}
return tenant;
}
Solved! Go to Solution.
Hi @zamsam6931 ,
You can check the following:
It seems to be caused by insufficient permissions or incorrect authentication, check if you have all the required permissions, you can check the details in the link below :
Embed content in your Power BI embedded analytics application - Power BI | Microsoft Learn
Check that the values entered are correct for tenantId, reportId, groupId and datasetId.
This is the related document, you can view this content:
Solved: Generate Embed Token For Create Issue - Microsoft Fabric Community
Solved: Creating datasource using Power BI RestAPI - Microsoft Fabric Community
c# - Operation returned an invalid status code 'Unauthorized'' - Stack Overflow
Best Regards,
Liu Yang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @zamsam6931 ,
You can check the following:
It seems to be caused by insufficient permissions or incorrect authentication, check if you have all the required permissions, you can check the details in the link below :
Embed content in your Power BI embedded analytics application - Power BI | Microsoft Learn
Check that the values entered are correct for tenantId, reportId, groupId and datasetId.
This is the related document, you can view this content:
Solved: Generate Embed Token For Create Issue - Microsoft Fabric Community
Solved: Creating datasource using Power BI RestAPI - Microsoft Fabric Community
c# - Operation returned an invalid status code 'Unauthorized'' - Stack Overflow
Best Regards,
Liu Yang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.