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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

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
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.