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

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.

Reply
Wahidm
Regular Visitor

Embed for customers- Fail to initialize - Could not resolve cluster

Hi, 

 

I am trying to use PowerBi Embeded in our application for our customers, however I get the following:

 

> Json Object
{
"message": "LoadReportFailed",
"detailedMessage": "Fail to initialize - Could not resolve cluster",
"errorCode": "403",
"level": 6,
"technicalDetails": {
"requestId": "5ccfb85d-9a69-49b4-b80f-1706f36bd590"
}
}

 

What am I doing?

This is my app settings:

"AppSettings": {
    "AuthorityUri": "https://login.windows.net/common/oauth2/authorize/",
    "ResourceUrl": "https://analysis.windows.net/powerbi/api",
    "RedirectUrl": "http://localhost:21638",
    "ApiUrl": "https://api.powerbi.com/",
    "ApplicationId": "MYAPPLICATIONID",
    "LoggingRequestUrl": "https://login.microsoftonline.com/common/oauth2/token",
    "GroupId": "MY WORKSPACE ID",
    "ReportID": "MY REPORTID",
    "ApplicationSecret": "MY APP SECRET",
    "Username": "POWERBI PRO USER ACCOUNT EMAIL",
    "Password": "MY PASSWORD"
   }

I get the Token using:

            var authorityUrl = $"https://login.microsoftonline.com/GROUPACCOUNTURL/oauth2/token";

            var oauthEndpoint = new Uri(authorityUrl);

            using (var client = new HttpClient())
            {
                var result = await client.PostAsync(oauthEndpoint, new FormUrlEncodedContent(new[]
                {
                     new KeyValuePair<string, string>("resource", AppSettings.ResourceUrl),
                     new KeyValuePair<string, string>("client_id", AppSettings.ApplicationId),
                     new KeyValuePair<string, string>("client_secret", AppSettings.ApplicationSecret),
                     new KeyValuePair<string, string>("grant_type", "password"),
                     new KeyValuePair<string, string>("username", AppSettings.Username),
                     new KeyValuePair<string, string>("password",AppSettings.Password),
                     new KeyValuePair<string, string>("scope", "openid"),
                 }));

                var content = await result.Content.ReadAsStringAsync();

                var authenticationResult = JsonConvert.DeserializeObject<OAuthResult>(content);
                return (new TokenCredentials(authenticationResult.AccessToken, "Bearer"), authenticationResult.AccessToken);

I then do the following:

 using (var powerBiClient = new PowerBIClient(new Uri(AppSettings.ApiUrl), credential.tokenCredentials))
            {
                var powerBiReport = powerBiClient.Reports.GetReportInGroup(AppSettings.GroupId, reportId);

                if (powerBiReport != null)
                {
                    var rowLevelSecurityIdentity = new List<EffectiveIdentity>
                                                       {
                                                           new EffectiveIdentity(name,
                                                               roles: new List<string> {role},
                                                               datasets: new List<string> {powerBiReport.DatasetId})
                                                       };
                    
                    var powerBiTokenRequestParameters = new GenerateTokenRequest("view", powerBiReport.DatasetId, identities: rowLevelSecurityIdentity);

                    var powerBiTokenResponse = powerBiClient.Reports.GenerateTokenInGroup(AppSettings.GroupId,powerBiReport.Id, powerBiTokenRequestParameters);

                    powerBIModel.EmbedUrl = powerBiReport.EmbedUrl;
                    powerBIModel.ReportId = powerBiReport.Id;
                    powerBIModel.AccessToken = powerBiTokenResponse.Token;

                }
  • I have set up the resource and the dedicated capacity in Azure
  • I have the diamond showing on the Workspace in PowerBi
  • I am the master user and I also have a PowerBi Pro account
  • It manages to get embed Url and access token but nothing shows up. I run the embed url, access token and report Id on the power bi playground site and get the error json above.

Can anyone help please?

 

Thanks

1 REPLY 1
MattStannett
Frequent Visitor

LoadReportFailedFail to initialize - Couldn't resolve cluster403* Bad access token * Embed type doesn't match token type

 

As per https://docs.microsoft.com/en-us/power-bi/developer/embedded-troubleshoot

 

My code is pretty similar and it works:

 

public async Task<AzureToken> GetAzureTokenDataAsync()
		{
			string authorityUrl = $"{_azureSettings.Instance}{_azureSettings.TenantId}/oauth2/token";

			Uri oauthEndpoint = new Uri(authorityUrl);

			using (HttpClient httpClient = new HttpClient())
			{
				HttpResponseMessage responseMessage = await httpClient.PostAsync(oauthEndpoint, new FormUrlEncodedContent(new[]
				{
					 new KeyValuePair<string, string>("resource", _powerBiSettings.ResourceUrl),
					 new KeyValuePair<string, string>("client_id", _azureSettings.ClientId),
					 new KeyValuePair<string, string>("grant_type", "password"),
					 new KeyValuePair<string, string>("username", _powerBiSettings.Username),
					 new KeyValuePair<string, string>("password", _powerBiSettings.Password),
					 new KeyValuePair<string, string>("scope", "openid"),
				 }));

				string responseText = await responseMessage.Content.ReadAsStringAsync();

				OAuthResult authenticationResult = JsonConvert.DeserializeObject<OAuthResult>(responseText);

				TokenCredentials tokenCredentials = new TokenCredentials(authenticationResult.AccessToken, "Bearer");

				return new AzureToken(tokenCredentials, authenticationResult.AccessToken);
			}
		}

		private class OAuthResult
		{
			[JsonProperty("token_type")]
			public string TokenType { get; set; }

			[JsonProperty("scope")]
			public string Scope { get; set; }

			[JsonProperty("expires_in")]
			public int ExpiresIn { get; set; }

			[JsonProperty("ext_expires_in")]
			public int ExtExpiresIn { get; set; }

			[JsonProperty("expires_on")]
			public int ExpiresOn { get; set; }

			[JsonProperty("not_before")]
			public int NotBefore { get; set; }

			[JsonProperty("resource")]
			public Uri Resource { get; set; }

			[JsonProperty("access_token")]
			public string AccessToken { get; set; }

			[JsonProperty("refresh_token")]
			public string RefreshToken { get; set; }
		}

public async Task<EmbeddedReportConfig> GetReportForIdAsync(Guid reportId, string name, string roles)
		{
			var result = new EmbeddedReportConfig();

			try
			{
				AzureToken azureToken = await _authenticationHandler.GetAzureTokenDataAsync();

				using (PowerBIClient powerBiClient = new PowerBIClient(new Uri(_powerBiSettings.ApiUrl), azureToken.TokenCredentials))
				{
					Report powerBiReport = await powerBiClient.Reports.GetReportAsync(_powerBiSettings.WorkspaceId, reportId.ToString());

					List<EffectiveIdentity> rowLevelSecurityIdentity = new List<EffectiveIdentity>
					{
						new EffectiveIdentity(
							name,
							//roles: new List<string> { role },
							datasets: new List<string> {powerBiReport.DatasetId}
						)
					};

					GenerateTokenRequest powerBiTokenRequestParameters = new GenerateTokenRequest("View", powerBiReport.DatasetId, false, rowLevelSecurityIdentity);

					EmbedToken powerBiTokenResponse = await powerBiClient.Reports.GenerateTokenInGroupAsync(_powerBiSettings.WorkspaceId, powerBiReport.Id, powerBiTokenRequestParameters);

					return new EmbeddedReportConfig
					{
						Id = powerBiReport.Id,
						Name = powerBiReport.Name,
						EmbedUrl = powerBiReport.EmbedUrl,
						AccessToken = powerBiTokenResponse.Token
					};
				}
			}
			catch (HttpOperationException ex)
			{
				// https://community.powerbi.com/t5/Developer/quot-shouldn-t-have-effective-identity-quot-error-when-passing/td-p/433730
				// https://docs.microsoft.com/en-us/power-bi/developer/embedded-row-level-security
				//Bad Request
				var content = ex.Response.Content;
				Console.WriteLine(content);

				return null;
			}
		}

There is also this https://stackoverflow.com/a/52998483/5209435. I hope this helps. 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.