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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
zamsam6931
Advocate II
Advocate II

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
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

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.

Top Solution Authors