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
daveParso
Frequent Visitor

POST 403(forbidden) after dashboard has been embedded

I'm using an app owns data setup with power BI embedded and have added functionality for switching between and refreshing dashboards. However after the first embed of a dashboard i am confronted with 4 POST 403 errors in chrome console and after this any refresh or switch just leaves a blank dashboard. below is an image that is representative of what is in the console after the first embed:

To be clear the first embed works fine and the dashboard is visible as expected but any subsequent attempts to change or refresh leave me with a blank screen

1 ACCEPTED SOLUTION
daveParso
Frequent Visitor

So its a little bit of a hack but i managed to get rid of the unauthorized errors by doing embedURL.replace("https://app", "https://msit") still unsure why requesting the url feeds back app but hey this got rid of the errors. However this hasnt actually changed the fact that running powerbi.embed again leaves me with a blank dashboard instead of refreshing like it does for reports. At this point I have given up on automatic refreshes for dashboards. switching between dashboards works now at the very least so I'm going to mark this as the solution unless anything better is posted.

View solution in original post

4 REPLIES 4
daveParso
Frequent Visitor

So its a little bit of a hack but i managed to get rid of the unauthorized errors by doing embedURL.replace("https://app", "https://msit") still unsure why requesting the url feeds back app but hey this got rid of the errors. However this hasnt actually changed the fact that running powerbi.embed again leaves me with a blank dashboard instead of refreshing like it does for reports. At this point I have given up on automatic refreshes for dashboards. switching between dashboards works now at the very least so I'm going to mark this as the solution unless anything better is posted.

import React, { Component } from 'react';
import Cookies from 'universal-cookie';
import { Redirect } from 'react-router-dom';

import { PowerBIEmbed } from 'powerbi-client-react';
import * as pbi from 'powerbi-client';

import { getAsyncPowerBi, getAsyncPowerBiToken } from '../Services/GetAPI';

import { PostPowerBI } from '../Services/PostAPI';
import { MsalProvider, MsalContext } from '@azure/msal-react';
import { loginRequest } from '../../authConfig';

import { getMenuData } from '../Services/MenuAccess';
const cookies = new Cookies();
const powerbi = new pbi.service.Service(
pbi.factories.hpmFactory,
pbi.factories.wpmpFactory,
pbi.factories.routerFactory
);

var models = pbi.models;
var tokenType = pbi.models.TokenType.Aad;

class Dashboards extends Component {
static contextType = MsalContext;

constructor(props) {
super(props);

this.state = {
embedUrl: '',
Data: [],
token: '',
reportToshow:false
};
}

getPoswerBI = async () => {
let res = await PostPowerBI(
'https://api.powerbi.com/v1.0/myorg/dashboards',
cookies.get('AccessToken')
);
console.log('Power', res);
if (res && res.value && res.value.length > 0) {
this.setState({
Data: res.value,
});
await this.handleChangeDashboard(res.value[6].id)

}


};
getDataMenu = async () => {
let res = await getMenuData();
if (res.USER_CLIENT) {
this.setState({
ClientData: res.USER_CLIENT,
});
}
};



hadleReport =() =>{
this.setState({
reportToshow:true
})
}

handleChangeDashboard = (embedDashboardId) =>{
var accessToken = cookies.get('AccessToken');
this.setState(prevState =>{
let {reportToshow} = prevState;
reportToshow = false;

return {reportToshow}
})

accessToken = accessToken.replace("Bearer ","")

// Read embed URL from Model
var embedUrl = `https://msit.powerbi.com/dashboardEmbed?dashboardId=${embedDashboardId}`;

// Read dashboard Id from Model
var embedDashboardId = embedDashboardId;

// Get models. models contains enums that can be used.
var models = window['powerbi-client'].models

console.log(models);

// Embed configuration used to describe the what and how to embed.
// This object is used when calling powerbi.embed.
// This also includes settings and options such as filters.
// You can find more information at https://github.com/Microsoft/PowerBI-JavaScript/wiki/Embed-Configuration-Details.
var config = {
type: 'dashboard',
tokenType: models.TokenType.Aad,
accessToken: accessToken,
embedUrl: embedUrl,
id: embedDashboardId
};

// Get a reference to the embedded dashboard HTML element
var dashboardContainer = document.getElementById("dashboardContainer");
powerbi.reset(dashboardContainer);

//$('#dashboardContainer')[0] ;

// Embed the dashboard and display it within the div container.
var dashboard = powerbi.embed(dashboardContainer, config);
dashboard.on("tileClicked", function (event) {
this.hadleReport();
var objTileClick = JSON.parse(JSON.stringify(event.detail, null, " "));

var embedUrlReport = objTileClick.reportEmbedUrl;
var reportId = embedUrlReport.substring((embedUrlReport.indexOf("reportId=") + 9));
reportId = reportId.substring(0, reportId.indexOf("groupId")-1);
var tileIdSelected = objTileClick.tileId;
var pageNameSelected = objTileClick.pageName;

console.log("embedUrlReport: "+ embedUrlReport);
console.log("reportId: "+ reportId);
console.log("tileIdSelected: "+ tileIdSelected);
console.log("pageNameSelected: "+ pageNameSelected);


var configReport = {
type: 'report',
accessToken: accessToken,
embedUrl: embedUrlReport,
id: reportId,
tileId:tileIdSelected,
pageName:pageNameSelected,
settings: {
filterPaneEnabled: true,
navContentPaneEnabled: true
}
};

var reportContainer = document.getElementById("dashboardContainer2");

powerbi.reset(reportContainer);
// Embed the report and display it within the div container.
var report = powerbi.embed(reportContainer, configReport);

 

}.bind(this))
}
async componentDidMount() {
await this.getPoswerBI();
await this.getDataMenu();


}

render() {
if (cookies.get('token') == null || cookies.get('token') === undefined) {
return <Redirect to="/" />;
}


const { Data, reportToshow } = this.state;
return (
<div>
<div className="pagetitle">Dashboard</div>
<div className="dbmenu">
<ul>
{Data &&
Data.map((item, i) => (
<li onClick={()=>this.handleChangeDashboard(item.id)} key={'inv' + i}>{item.displayName}</li>
))}
</ul>
<div className="clr"></div>
</div>

<div id="dashboardContainer" style={{display:reportToshow ===false ? 'block':'none'}}></div>

<div id="dashboardContainer2" style={{display:reportToshow ===true ? 'block':'none'}}></div>


</div>
);
}
}

export default Dashboards;

Eric_Zhang
Employee
Employee


@daveParso wrote:

I'm using an app owns data setup with power BI embedded and have added functionality for switching between and refreshing dashboards. However after the first embed of a dashboard i am confronted with 4 POST 403 errors in chrome console and after this any refresh or switch just leaves a blank dashboard. below is an image that is representative of what is in the console after the first embed:

To be clear the first embed works fine and the dashboard is visible as expected but any subsequent attempts to change or refresh leave me with a blank screen


@daveParso

I'm not able to produce this issue. To exclude the cause from your code, could you try to embed with the attached html file? If the error still exists, please fiddler the network traffic when refreshing and submit a support ticket with the trace file.

So the embed worked fine in the attached html file. The one difference i noticed between the two was i was using https://app.powerbi.com/dashboardEmbed? in my embed url where as the html file you provided used https://msit.powerbi.com/dashboardEmbed? However if I modify my embed url to include msit instead of api I get "an invalid status code NotFound". Its also curious to me that my report embedding works just fine with app without throwing the error that dashboards are.

 

Edit:

After some more digging i have found that using dashboard.embedUrl in the controller is returning the https://app.powerbi.com link however if i replace this by hardcoding in the msit one it works fine. as far as im aware though i dont have any control over what that value is so is there some way for me to change this as obviously hardcoding in what dashboard is displayed is not suitbale for the overall product.

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.

Top Kudoed Authors