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

Try your skills in the Power BI Dataviz World Championship! Round one ends June 26. Join now

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
Fabric Data Days is here Carousel

Fabric Data Days 2026

Don't miss out on Data Days, June 15 through August 7. Learn Fabric, Power BI, SQL, AI and more.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.