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?
Please guide me.
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((req, res) => {
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(options, function (error, response) {
if (error) throw new Error(error);
var jsonObj = JSON.parse(response.body);
var options1 = {
'method': 'GET',
'headers': {
'Authorization': 'Bearer ' + jsonObj.access_token
}
};
request(options1, function (error, response) {
if (error) throw 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(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});