Forum Discussion

ronnoc's avatar
ronnoc
Advocate II
9 years ago
Solved

power bi java script API - Finally have access tokens but no staticReportUrl

I have spent a good amount of time trying to properly embed a report using the javascript API, as far as I know the js API is the only way to get interactivity within embedded reports which is necess...
  • Eric_Zhang's avatar
    9 years ago

    ronnoc

    I embed my own reports with a sample code as below. Replace the id, token and embed url with yourself's, save it as a html file and open it in Chrome/IE/FF.

    <html>
    
     <script src="../jquery.js"></script>  
     <script src="../powerbi.js"></script> 
    
    <script type="text/javascript">
    window.onload = function () {
     
    var embedConfiguration = {
        type: 'report',
        accessToken: 'yourtokenhere',
        id: '51309815-f35b-xxxx-acb8-bc7245cd8f0c',
        //for Power BI Embedded
    	//embedUrl: 'https://embedded.powerbi.com/appTokenReportEmbed?reportId=734503cf-1309-4892-xxxx-791d62c15x44' 
    	//for Power BI REST API
    	embedUrl: 'https://msit.powerbi.com/reportEmbed?reportId=51309815-f35b-xxxx-acb8-bc7245cd8f0c'
    }; 
    
    var $reportContainer = $('#reportContainer');
     
    var report = powerbi.embed($reportContainer.get(0), embedConfiguration);
      
    report.fullscreen();  
    
    }
    </script>
    
    <div id="reportContainer"></div>
    
    </html>