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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
oflok000
Frequent Visitor

Power Bi Js Api Example From GitHub

Hello

I was learning Power Bi Js Api from github and then when I start make my example. I got this problemScreen Shot 2018-01-30 at 4.39.26 PM.png

this is my Code. (I am using angular. I took access code,url,id from sample form github)

// app/app.component.ts

import { Component, OnInit } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import * as pbi from 'powerbi-client';


declare const $; 

@Component({
  selector: 'app-root',
  templateUrl:'app.component.html',
  styles: [``]
})
export class AppComponent implements OnInit {
    
    constructor(private http: HttpClient){}
    
    ngOnInit(){ 
        
        this.showReport();
            
    }
    
    showReport() {
    // Report's Secured Token
    let accessToken = 'H4sIAAAAAAAEAB2Wxw6shhJE_-VusUSGwZIX5JwzOzJDzsl6__5G3vei-6iquv79Y6VPP6XFn7__NBYvBIOr0ykKgg-FRvn-3Pa5iS1JnzN7fgswUIA8b96PLi660L_XS9HsrY9ULGBGnPeAWRJNB7jWCUgvuTlqEejfGk6f5iTlzWUfz3FAATeQqbg7eQqL-nPazEfJIf-qqdelQs5YsOV0bls9ZrrkPpmn-22p8L2BBAv8kuUjgcON3Cyo04rMGWZDAnGHlEjr9H2rYm9PV7OFaM4q9VRRV4RTQwE_468LlmJhPlE0iS6zPvz1yVF6t7NbldPkk-ZpnJ5QQxZfJJ4lSUF4Frf381xC4_OwLkJ6tjaMfGQxWEryO9IA41SQ7pxKmIFRDV5_n_dMUBUEo-AaGDM7eA_VJ6CC_DSuFW4N2kJvZZCvY5ydylmwb8qMmVTKX4VzaL5UY7lexoZi-O9UVUIXa9rAVA6KDYN_X8iTLGulhKUjswSrsiWeoZtOvZ-qn3feRmM_wbdWDWPponRcyRbHcOgvTABtglDi3lMOlyXN4KbrgQURy4PO-Og2gYAJVvmmYQAw2gEOj2idj7Yw8txPEe1msF-F6fqUzA9s2ps5EIHy9cRsfZ9YF7EkbZg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hg19-SXaGHIWDoo81HTfj19pXgzl5e2uFdsGmTnumJkssqLDIZMPFA89gZYchMw-GSVdEdNptIIA5Z4mGHY5BXhuehxS3hVz06Psl6rJBiU92uqP8z_-z8oE56sLgsAAA==';

    // Embed URL
    let embedUrl = 'https://app.powerbi.com/reportEmbed?reportId=bd851208-5592-4e3e-ba72-5cfdfc39f41c&groupId=9166cf8d-d5fc-405e-bdc7-47e414da08fe';

    // Report ID
    let embedReportId = 'bd851208-5592-4e3e-ba72-5cfdfc39f41c';

    var models = pbi.models;
 
// We give All permissions to demonstrate switching between View and Edit mode and saving report.
    var permissions = models.Permissions.All
        
    // Configuration used to describe the what and how to embed.
    // This object is used when calling powerbi.embed.
    // This also includes settings and options such as filters.
    // You can find more information at https://github.com/Microsoft/PowerBI-JavaScript/wiki/Embed-Configuration-Details.
    let config= {
    type: 'report',
    //tokenType: tokenType == '0' ? models.TokenType.Aad : models.TokenType.Embed,
    accessToken: accessToken,
    embedUrl: embedUrl,
    id: embedReportId,
    permissions: permissions,
    settings: {
        filterPaneEnabled: true,
        navContentPaneEnabled: true
    }
}

    // Grab the reference to the div HTML element that will host the report.
    let reportContainer = <HTMLElement>document.getElementById('reportContainer');

    // Embed the report and display it within the div container.
    let powerbi = new pbi.service.Service(pbi.factories.hpmFactory, pbi.factories.wpmpFactory, pbi.factories.routerFactory);
    let report = powerbi.embed(reportContainer, config);

        console.log(report);
        
    // Report.off removes a given event handler if it exists.
    report.off("loaded");

    // Report.on will add an event handler which prints to Log window.
    report.on("loaded", function() {
        console.log("Loaded");
    });
}

        
    
}

I alredy try everithing but I have no idea why my code doesnt work. It's the same code what they have

2 REPLIES 2
v-ljerr-msft
Microsoft Employee
Microsoft Employee

Hi @oflok000,


I was learning Power Bi Js Api from github and then when I start make my example. I got this problemScreen Shot 2018-01-30 at 4.39.26 PM.png

this is my Code. (I am using angular. I took access code,url,id from sample form github)


The access token, url, id from the sample won't work in your application/code. You need to use your own access token, url, id.

 

So you have to create Power BI account, and upload your reports to the created account. Then, you can call Power BI APIs to generate Embed Token for reports, dashboards or tiles you want to embed. For more information about embedding entities using Embed Tokens, please visit Embed Token DocumentationSmiley Happy

 

Regards

Hello

Thank you for respond. Actually I can use any accesss tokken my tokken was embed but I found example with access code.

This link https://powerbiembedapi.azurewebsites.net/api/reports/c52af8ab-0468-4165-92af-dc39858d66ad return json with access code.

 

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.