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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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