<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Embed for customers- Fail to initialize - Could not resolve cluster in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/Embed-for-customers-Fail-to-initialize-Could-not-resolve-cluster/m-p/648364#M18862</link>
    <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to use PowerBi&amp;nbsp;Embeded&amp;nbsp;in our application for our customers, however I get the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;gt; Json Object&lt;BR /&gt;{&lt;BR /&gt;"message": "LoadReportFailed",&lt;BR /&gt;"detailedMessage": "Fail to initialize - Could not resolve cluster",&lt;BR /&gt;"errorCode": "403",&lt;BR /&gt;"level": 6,&lt;BR /&gt;"technicalDetails": {&lt;BR /&gt;"requestId": "5ccfb85d-9a69-49b4-b80f-1706f36bd590"&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;What am I doing?&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;This is my app settings:&lt;/P&gt;&lt;PRE&gt;"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"
   }&lt;/PRE&gt;&lt;P&gt;I get the Token using:&lt;/P&gt;&lt;PRE&gt;            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&amp;lt;string, string&amp;gt;("resource", AppSettings.ResourceUrl),
                     new KeyValuePair&amp;lt;string, string&amp;gt;("client_id", AppSettings.ApplicationId),
                     new KeyValuePair&amp;lt;string, string&amp;gt;("client_secret", AppSettings.ApplicationSecret),
                     new KeyValuePair&amp;lt;string, string&amp;gt;("grant_type", "password"),
                     new KeyValuePair&amp;lt;string, string&amp;gt;("username", AppSettings.Username),
                     new KeyValuePair&amp;lt;string, string&amp;gt;("password",AppSettings.Password),
                     new KeyValuePair&amp;lt;string, string&amp;gt;("scope", "openid"),
                 }));

                var content = await result.Content.ReadAsStringAsync();

                var authenticationResult = JsonConvert.DeserializeObject&amp;lt;OAuthResult&amp;gt;(content);
                return (new TokenCredentials(authenticationResult.AccessToken, "Bearer"), authenticationResult.AccessToken);&lt;/PRE&gt;&lt;P&gt;I then do the following:&lt;/P&gt;&lt;PRE&gt; 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&amp;lt;EffectiveIdentity&amp;gt;
                                                       {
                                                           new EffectiveIdentity(name,
                                                               roles: new List&amp;lt;string&amp;gt; {role},
                                                               datasets: new List&amp;lt;string&amp;gt; {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;

                }&lt;/PRE&gt;&lt;UL&gt;&lt;LI&gt;I have set up the resource and the dedicated capacity in Azure&lt;/LI&gt;&lt;LI&gt;I have the diamond showing on the Workspace in PowerBi&lt;/LI&gt;&lt;LI&gt;I am the master user and I also have a PowerBi&amp;nbsp;Pro account&lt;/LI&gt;&lt;LI&gt;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&amp;nbsp;above.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Can anyone help please?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
    <pubDate>Wed, 20 Mar 2019 15:57:38 GMT</pubDate>
    <dc:creator>Wahidm</dc:creator>
    <dc:date>2019-03-20T15:57:38Z</dc:date>
    <item>
      <title>Embed for customers- Fail to initialize - Could not resolve cluster</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Embed-for-customers-Fail-to-initialize-Could-not-resolve-cluster/m-p/648364#M18862</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to use PowerBi&amp;nbsp;Embeded&amp;nbsp;in our application for our customers, however I get the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;gt; Json Object&lt;BR /&gt;{&lt;BR /&gt;"message": "LoadReportFailed",&lt;BR /&gt;"detailedMessage": "Fail to initialize - Could not resolve cluster",&lt;BR /&gt;"errorCode": "403",&lt;BR /&gt;"level": 6,&lt;BR /&gt;"technicalDetails": {&lt;BR /&gt;"requestId": "5ccfb85d-9a69-49b4-b80f-1706f36bd590"&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;What am I doing?&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;This is my app settings:&lt;/P&gt;&lt;PRE&gt;"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"
   }&lt;/PRE&gt;&lt;P&gt;I get the Token using:&lt;/P&gt;&lt;PRE&gt;            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&amp;lt;string, string&amp;gt;("resource", AppSettings.ResourceUrl),
                     new KeyValuePair&amp;lt;string, string&amp;gt;("client_id", AppSettings.ApplicationId),
                     new KeyValuePair&amp;lt;string, string&amp;gt;("client_secret", AppSettings.ApplicationSecret),
                     new KeyValuePair&amp;lt;string, string&amp;gt;("grant_type", "password"),
                     new KeyValuePair&amp;lt;string, string&amp;gt;("username", AppSettings.Username),
                     new KeyValuePair&amp;lt;string, string&amp;gt;("password",AppSettings.Password),
                     new KeyValuePair&amp;lt;string, string&amp;gt;("scope", "openid"),
                 }));

                var content = await result.Content.ReadAsStringAsync();

                var authenticationResult = JsonConvert.DeserializeObject&amp;lt;OAuthResult&amp;gt;(content);
                return (new TokenCredentials(authenticationResult.AccessToken, "Bearer"), authenticationResult.AccessToken);&lt;/PRE&gt;&lt;P&gt;I then do the following:&lt;/P&gt;&lt;PRE&gt; 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&amp;lt;EffectiveIdentity&amp;gt;
                                                       {
                                                           new EffectiveIdentity(name,
                                                               roles: new List&amp;lt;string&amp;gt; {role},
                                                               datasets: new List&amp;lt;string&amp;gt; {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;

                }&lt;/PRE&gt;&lt;UL&gt;&lt;LI&gt;I have set up the resource and the dedicated capacity in Azure&lt;/LI&gt;&lt;LI&gt;I have the diamond showing on the Workspace in PowerBi&lt;/LI&gt;&lt;LI&gt;I am the master user and I also have a PowerBi&amp;nbsp;Pro account&lt;/LI&gt;&lt;LI&gt;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&amp;nbsp;above.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Can anyone help please?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Wed, 20 Mar 2019 15:57:38 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Embed-for-customers-Fail-to-initialize-Could-not-resolve-cluster/m-p/648364#M18862</guid>
      <dc:creator>Wahidm</dc:creator>
      <dc:date>2019-03-20T15:57:38Z</dc:date>
    </item>
    <item>
      <title>Re: Embed for customers- Fail to initialize - Could not resolve cluster</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Embed-for-customers-Fail-to-initialize-Could-not-resolve-cluster/m-p/649794#M18878</link>
      <description>&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;LoadReportFailed&lt;/TD&gt;&lt;TD&gt;Fail to initialize - Couldn't resolve cluster&lt;/TD&gt;&lt;TD&gt;403&lt;/TD&gt;&lt;TD&gt;* Bad access token * Embed type doesn't match token type&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As per&amp;nbsp;&lt;A href="https://docs.microsoft.com/en-us/power-bi/developer/embedded-troubleshoot" target="_self"&gt;https://docs.microsoft.com/en-us/power-bi/developer/embedded-troubleshoot&lt;/A&gt;.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My code is pretty similar and it works:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;public async Task&amp;lt;AzureToken&amp;gt; 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&amp;lt;string, string&amp;gt;("resource", _powerBiSettings.ResourceUrl),
					 new KeyValuePair&amp;lt;string, string&amp;gt;("client_id", _azureSettings.ClientId),
					 new KeyValuePair&amp;lt;string, string&amp;gt;("grant_type", "password"),
					 new KeyValuePair&amp;lt;string, string&amp;gt;("username", _powerBiSettings.Username),
					 new KeyValuePair&amp;lt;string, string&amp;gt;("password", _powerBiSettings.Password),
					 new KeyValuePair&amp;lt;string, string&amp;gt;("scope", "openid"),
				 }));

				string responseText = await responseMessage.Content.ReadAsStringAsync();

				OAuthResult authenticationResult = JsonConvert.DeserializeObject&amp;lt;OAuthResult&amp;gt;(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&amp;lt;EmbeddedReportConfig&amp;gt; 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&amp;lt;EffectiveIdentity&amp;gt; rowLevelSecurityIdentity = new List&amp;lt;EffectiveIdentity&amp;gt;
					{
						new EffectiveIdentity(
							name,
							//roles: new List&amp;lt;string&amp;gt; { role },
							datasets: new List&amp;lt;string&amp;gt; {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;
			}
		}&lt;/PRE&gt;&lt;P&gt;There is also this&amp;nbsp;&lt;A href="https://stackoverflow.com/a/52998483/5209435" target="_self"&gt;https://stackoverflow.com/a/52998483/5209435&lt;/A&gt;.&amp;nbsp;I hope this helps.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Mar 2019 21:39:09 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Embed-for-customers-Fail-to-initialize-Could-not-resolve-cluster/m-p/649794#M18878</guid>
      <dc:creator>MattStannett</dc:creator>
      <dc:date>2019-03-20T21:39:09Z</dc:date>
    </item>
  </channel>
</rss>

