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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
Juan_Carlos_AT
New Member

Get report failed

Hi everyone, 

 

How to fix https://api.powerbi.com/powerbi/globalservice/v201606/clusterdetails (401).

 

I am embedded in my .net framework (webforms) application, a paginated report from power bi service, when I press a button I need the report to appear.

 

When I click the button, the report should open in a container, but I get the error I mentioned above. The strange thing is that the report can be seen using the Microsoft application 'Power BI Embedded Sample', but it is not shown in my application.

 

Juan_Carlos_AT_0-1694203396421.png

 

 

In the Microsoft application, however, it can be seen embedded

 

Juan_Carlos_AT_1-1694203396423.png

ASPX File:

 

            (javascript)

 

    <script type="text/javascript">

        function embedReport() {

 

            var models = window['powerbi-client'].models;;

            let embedConfiguration = {

                accessToken: '<%= LiteralAccessToken.Text %>',

                embedUrl: '<%= LiteralEmbedUrl.Text %>',

                id: '<%= LiteralReportId.Text %>',

                tokenType: models.TokenType.Aad,

                type: 'report'

            };

 

            let dashboardContainer = $('#reportContainer')[0];

            let dashboard = powerbi.embed(dashboardContainer, embedConfiguration);

        }

        document.addEventListener('DOMContentLoaded', function () {

            embedReport();

        });

    </script>

           

            (body)

            ...........................

    <asp:Literal ID="LiteralReportId" runat="server" Visible="false"></asp:Literal>

    <asp:Literal ID="LiteralEmbedUrl" runat="server" Visible="false"></asp:Literal>

    <asp:Literal ID="LiteralTokenType" runat="server" Visible="false"></asp:Literal>

    <asp:Literal ID="LiteralAccessToken" runat="server" Visible="false"></asp:Literal>

           

    <asp:Button ID="btnLoadReport" runat="server" OnClick="btnLoadReport_Click" Text="Cargar Reporte" />

    <div id="reportContainer" style="height: 600px; width: 100%;"></div>

            .............................

           

CS File:

 

    .............................................................................

    protected void btnLoadReport_Click(object sender, EventArgs e)

    {

        EmbedPowerBIReport().Wait();

    }

           

    private async Task EmbedPowerBIReport()

    {

        Guid groupId = new Guid("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");

        Guid reportId = new Guid("yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy");

 

        using (HttpClient httpClient = new HttpClient())

        {

            // Obtén el token de acceso

            var content = new FormUrlEncodedContent(new[]

            {

                new KeyValuePair<string, string>("grant_type", "client_credentials"),

                new KeyValuePair<string, string>("client_id", clientId),

                new KeyValuePair<string, string>("client_secret", clientSecret),

                new KeyValuePair<string, string>("scope", "https://analysis.windows.net/powerbi/api/.default")

            });

 

            System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;

            var tokenResponse = await httpClient.PostAsync("https://login.microsoftonline.com/zzzzzzzzzzzzzzzzzzzzzzzzzzzzz/oauth2/v2.0/token", content);

            var tokenContent = await tokenResponse.Content.ReadAsStringAsync();

            var token = Newtonsoft.Json.JsonConvert.DeserializeObject<TokenResponse>(tokenContent);

                                  

            TokenCredentials tokenCredentials = new TokenCredentials(token.access_token, "Bearer");

            using (var client = new PowerBIClient(new Uri(apiUrl), tokenCredentials))

            {

                var report = await client.Reports.GetReportInGroupAsync(groupId, reportId);

 

                LiteralReportId.Text = reportId.ToString();

                LiteralEmbedUrl.Text = report.EmbedUrl;

                LiteralTokenType.Text = token.token_type;

                LiteralAccessToken.Text = token.access_token;

 

            }

        }

        ScriptManager.RegisterStartupScript(this, GetType(), "embedReport", "embedReport();", true);

    }

    ...............................................................................

 

Help me please!

 

 

 

0 REPLIES 0

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.