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

Join the FabCon + SQLCon recap series. Up next: Power BI, Real-Time Intelligence, IQ and AI, and Data Factory take center stage. All sessions are available on-demand after the live show. Register now

Reply
zamsam6931
Regular Visitor

Microsoft.Rest.HttpOperationException: 'Operation returned an invalid status code 'Not Found''

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;
}

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

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.

View solution in original post

1 REPLY 1
Anonymous
Not applicable

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.

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

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

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

FabCon and SQLCon Highlights Carousel

FabCon &SQLCon Highlights

Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.