Forum Discussion

zamsam6931's avatar
zamsam6931
Advocate II
1 year ago
Solved

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 Reply