<?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 Error calling powerbi.embed() in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/Error-calling-powerbi-embed/m-p/1526916#M26644</link>
    <description>&lt;P&gt;Hi there,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to embed a simple Power BI report inside a ASP web (.NET Core) using controllers. I have already get correctly embedToken, embedURL and ReportID, but when i try to call powerbi.embed() to initialize the report i get the following error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;"ncaught TypeError: this.element.getAttribute is not a function&lt;BR /&gt;at e.t.getUniqueId (powerbi.min.js:2)&lt;BR /&gt;at e.t.populateConfig (powerbi.min.js:2)&lt;BR /&gt;at e.t (powerbi.min.js:2)&lt;BR /&gt;at new e (powerbi.min.js:5)&lt;BR /&gt;at t.embedNew (powerbi.min.js:2)&lt;BR /&gt;at t.embedInternal (powerbi.min.js:2)&lt;BR /&gt;at t.embed (powerbi.min.js:2)&lt;BR /&gt;at Object.&amp;lt;anonymous&amp;gt; (my-extension.js:125)&lt;BR /&gt;at u (jquery.min.js:2)&lt;BR /&gt;at Object.fireWith [as resolveWith] (jquery.min.js:2)"&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried the EmbedToken, embedUrls and ReportId in Power BI embed Playground and they works fine, but i get that problem in the code. I believe that the problem may reside in the powerbi.js file, but i have also tried with differents files, from nugget package and GitHub and i still have the same problem.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I left the code to get the tokens and initialice the Power BI Report below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;JS file to initialice the Report and Call API to get the tokens: Consider MyPanel as a simple pop-up properties panel&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;this._button.onClick = (ev) =&amp;gt; {
            this._enabled = !this._enabled;
            this._button.setState(this._enabled ? 0 : 1);
             //Execute an action here
             //if null, create docking panel

            if (this.panel == null) {
                this.panel = new MyPanel(this.viewer, this.viewer.container, 'myPanel', 'My Panel');
                this.panel.addVisibilityListener((show) =&amp;gt; {
                    this._button.setState(show ? 0 : 1);
                });
            }
            var request = jQuery.ajax({
                url: '/api/forge/PBI/url'
            });

            request.done(function (data) {
                console.log(data);
                // Read embed application token from textbox
                var txtAccessToken = data.accessToken;

                // Read embed URL from textbox
                var txtEmbedUrl = data.embedUrl;

                // Read report Id from textbox
                var txtEmbedReportId = data.reportId;

                var models = window['powerbi-client'].models;
                var permissions = models.Permissions.All;

                var config = {
                    type: 'report',
                    tokenType: models.TokenType.Embed,
                    accessToken: txtAccessToken,
                    embedUrl: txtEmbedUrl,
                    id: txtEmbedReportId,
                    permissions: permissions,
                    settings: {
                        panes: {
                            filters: {
                                visible: true
                            },
                            pageNavigation: {
                                visible: true
                            }
                        }
                    }
                };
                var div = $('#PowerBIEmbed');
                var report = powerbi.embed(div, config);
                
            });&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The C# files to get the tokens an respond to API request:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;[ApiController]
    public class PowerBi : ControllerBase
    {

        [HttpGet]
        [Route("/api/forge/PBI/url")]
        public EmbedConfig  GetPBIToken()
        {
            EmbedConfig pBIData =  PBICredentials.GetEmbedToken();
            return pBIData;          
        }


    }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;public class PBICredentials
    {
        public static EmbedConfig GetEmbedToken()
        {
            var a = new Configurations();
            using (var client = new PowerBIClient(new Uri(Configurations.ApiUrl), Authentication.GetTokenCredentials()))
            {
                // Retrieve the selected Report
                var Reports = client.Reports.GetReportsInGroup(Configurations.WorkspaceId);
                var Report = Reports.Value.FirstOrDefault();

                // Generate an embed token to view
                var generateTokenRequestParameters = new GenerateTokenRequest(TokenAccessLevel.View);
                var tokenResponse = client.Reports.GenerateTokenInGroup(Configurations.WorkspaceId, Report.Id, generateTokenRequestParameters);

                // Populate embed variables (to be passed client-side)
                EmbedConfig embed = new EmbedConfig()
                {
                    AccessToken = tokenResponse.Token,
                    EmbedUrl = Report.EmbedUrl,
                    ReportId = Report.Id
                };

                return embed;
            }
        }

    }

    public class EmbedConfig
    {
        [JsonPropertyName("accessToken")]
        public string AccessToken { get; set; }

        [JsonPropertyName("embedUrl")]
        public string EmbedUrl { get; set; }

        [JsonPropertyName("reportId")]
        public Guid ReportId { get; set; }
    }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Consider the authentification file and Configuration as in the Course "Developers in One Day" From microsoft Power BI: &lt;A href="https://www.youtube.com/playlist?list=PL1N57mwBHtN1AGWHnJMhtvJCIG_IlC07D" target="_blank" rel="noopener"&gt;https://www.youtube.com/playlist?list=PL1N57mwBHtN1AGWHnJMhtvJCIG_IlC07D&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any kind of help will be thanked!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best regards,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Carlos&lt;/P&gt;</description>
    <pubDate>Tue, 01 Dec 2020 16:10:17 GMT</pubDate>
    <dc:creator>crodrigueza</dc:creator>
    <dc:date>2020-12-01T16:10:17Z</dc:date>
    <item>
      <title>Error calling powerbi.embed()</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Error-calling-powerbi-embed/m-p/1526916#M26644</link>
      <description>&lt;P&gt;Hi there,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to embed a simple Power BI report inside a ASP web (.NET Core) using controllers. I have already get correctly embedToken, embedURL and ReportID, but when i try to call powerbi.embed() to initialize the report i get the following error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;"ncaught TypeError: this.element.getAttribute is not a function&lt;BR /&gt;at e.t.getUniqueId (powerbi.min.js:2)&lt;BR /&gt;at e.t.populateConfig (powerbi.min.js:2)&lt;BR /&gt;at e.t (powerbi.min.js:2)&lt;BR /&gt;at new e (powerbi.min.js:5)&lt;BR /&gt;at t.embedNew (powerbi.min.js:2)&lt;BR /&gt;at t.embedInternal (powerbi.min.js:2)&lt;BR /&gt;at t.embed (powerbi.min.js:2)&lt;BR /&gt;at Object.&amp;lt;anonymous&amp;gt; (my-extension.js:125)&lt;BR /&gt;at u (jquery.min.js:2)&lt;BR /&gt;at Object.fireWith [as resolveWith] (jquery.min.js:2)"&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried the EmbedToken, embedUrls and ReportId in Power BI embed Playground and they works fine, but i get that problem in the code. I believe that the problem may reside in the powerbi.js file, but i have also tried with differents files, from nugget package and GitHub and i still have the same problem.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I left the code to get the tokens and initialice the Power BI Report below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;JS file to initialice the Report and Call API to get the tokens: Consider MyPanel as a simple pop-up properties panel&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;this._button.onClick = (ev) =&amp;gt; {
            this._enabled = !this._enabled;
            this._button.setState(this._enabled ? 0 : 1);
             //Execute an action here
             //if null, create docking panel

            if (this.panel == null) {
                this.panel = new MyPanel(this.viewer, this.viewer.container, 'myPanel', 'My Panel');
                this.panel.addVisibilityListener((show) =&amp;gt; {
                    this._button.setState(show ? 0 : 1);
                });
            }
            var request = jQuery.ajax({
                url: '/api/forge/PBI/url'
            });

            request.done(function (data) {
                console.log(data);
                // Read embed application token from textbox
                var txtAccessToken = data.accessToken;

                // Read embed URL from textbox
                var txtEmbedUrl = data.embedUrl;

                // Read report Id from textbox
                var txtEmbedReportId = data.reportId;

                var models = window['powerbi-client'].models;
                var permissions = models.Permissions.All;

                var config = {
                    type: 'report',
                    tokenType: models.TokenType.Embed,
                    accessToken: txtAccessToken,
                    embedUrl: txtEmbedUrl,
                    id: txtEmbedReportId,
                    permissions: permissions,
                    settings: {
                        panes: {
                            filters: {
                                visible: true
                            },
                            pageNavigation: {
                                visible: true
                            }
                        }
                    }
                };
                var div = $('#PowerBIEmbed');
                var report = powerbi.embed(div, config);
                
            });&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The C# files to get the tokens an respond to API request:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;[ApiController]
    public class PowerBi : ControllerBase
    {

        [HttpGet]
        [Route("/api/forge/PBI/url")]
        public EmbedConfig  GetPBIToken()
        {
            EmbedConfig pBIData =  PBICredentials.GetEmbedToken();
            return pBIData;          
        }


    }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;public class PBICredentials
    {
        public static EmbedConfig GetEmbedToken()
        {
            var a = new Configurations();
            using (var client = new PowerBIClient(new Uri(Configurations.ApiUrl), Authentication.GetTokenCredentials()))
            {
                // Retrieve the selected Report
                var Reports = client.Reports.GetReportsInGroup(Configurations.WorkspaceId);
                var Report = Reports.Value.FirstOrDefault();

                // Generate an embed token to view
                var generateTokenRequestParameters = new GenerateTokenRequest(TokenAccessLevel.View);
                var tokenResponse = client.Reports.GenerateTokenInGroup(Configurations.WorkspaceId, Report.Id, generateTokenRequestParameters);

                // Populate embed variables (to be passed client-side)
                EmbedConfig embed = new EmbedConfig()
                {
                    AccessToken = tokenResponse.Token,
                    EmbedUrl = Report.EmbedUrl,
                    ReportId = Report.Id
                };

                return embed;
            }
        }

    }

    public class EmbedConfig
    {
        [JsonPropertyName("accessToken")]
        public string AccessToken { get; set; }

        [JsonPropertyName("embedUrl")]
        public string EmbedUrl { get; set; }

        [JsonPropertyName("reportId")]
        public Guid ReportId { get; set; }
    }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Consider the authentification file and Configuration as in the Course "Developers in One Day" From microsoft Power BI: &lt;A href="https://www.youtube.com/playlist?list=PL1N57mwBHtN1AGWHnJMhtvJCIG_IlC07D" target="_blank" rel="noopener"&gt;https://www.youtube.com/playlist?list=PL1N57mwBHtN1AGWHnJMhtvJCIG_IlC07D&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any kind of help will be thanked!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best regards,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Carlos&lt;/P&gt;</description>
      <pubDate>Tue, 01 Dec 2020 16:10:17 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Error-calling-powerbi-embed/m-p/1526916#M26644</guid>
      <dc:creator>crodrigueza</dc:creator>
      <dc:date>2020-12-01T16:10:17Z</dc:date>
    </item>
    <item>
      <title>Re: Error calling powerbi.embed()</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Error-calling-powerbi-embed/m-p/1532546#M26683</link>
      <description>&lt;P&gt;Does anyone know anything about it?&lt;/P&gt;</description>
      <pubDate>Fri, 04 Dec 2020 08:25:19 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Error-calling-powerbi-embed/m-p/1532546#M26683</guid>
      <dc:creator>crodrigueza</dc:creator>
      <dc:date>2020-12-04T08:25:19Z</dc:date>
    </item>
  </channel>
</rss>

