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
BalaKrish
Helper I
Helper I

PowerBI embedded Help - Code is below(Nodejs)

Dear all,

 

I am new to powerBI embedded.

I have built the below code Nodejs and Invoking Embed URL to display the report. But , it is not working.

 

I am confused about this. Am I doing completly wrong?

 

I feel that I completly lost of track . 

 

Please guide me.

Code :

 

const http = require('http');
const request = require('request')
var fs = require('fs');
var url = require('url');
var app = require("express")(); 
var bodyParser = require("body-parser"); 
var embedUrlpassing;

const hostname = '127.0.0.1';
const port = 3000;
const server = http.createServer((reqres=> {
  res.statusCode = 200;
  res.setHeader('Content-Type''text/html');

var options = {
  'method': 'POST',
  'headers': {
    'Content-Type': 'application/x-www-form-urlencoded'
  },
  formData: {
    'grant_type': 'password',
    'scope': 'openid',
    'client_id': '3202f8a8-b9db-46a7-a68c-a744a4ba0289',
    'username': '######@####.com',
    'password': '######'
  }
};
request(optionsfunction (errorresponse) { 
if (errorthrow new Error(error);
var jsonObj = JSON.parse(response.body);
var options1 = {
  'method': 'GET',
  'headers': {
    'Authorization': 'Bearer ' + jsonObj.access_token
  }
};
request(options1function (errorresponse) { 
  if (errorthrow new Error(error);
  var embededJSON = JSON.parse(response.body);
  var embedUrlpassing =JSON.stringify(embededJSON.value[0].embedUrl);

  //res.end('<html>'+ embedUrlpassing +'</html>');

  //res.end('<!DOCTYPE html><html><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1"><body><iframe width="1140" height="541.25" src='+embedUrlpassing+' frameborder="0" allowFullScreen="true"></iframe></body></html>');

  res.end('<!DOCTYPE html><html><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1"><head> <script>document.location.replace('+embedUrlpassing +');</script></head><body></body></html>');
  });

});

});

server.listen(porthostname, () => {
  console.log(`Server running at http://${hostname}:${port}/`);
});

 

 

1 REPLY 1
fdanielsouza
Helper I
Helper I

Well, there are problems with your code. One of them is that you're not using Promises, so your calls aren't waiting for your token to be received from the first request. The other problem I see is that you're not using routes. You're not pointing what should happen to which url the user goes.

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.