microsoft / powerbi-client-react

Power BI for React which provides components and services to enabling developers to easily embed Power BI reports into their applications.
MIT License
308 stars 98 forks source link

Seeing error "Embed URL is invalid for this scenario" when trying to loan any report in the embed component #94

Closed msnyder-msft closed 9 months ago

msnyder-msft commented 1 year ago

We are trying to embed a report in our react app but are consistently getting blocked by this error "Embed URL is invalid for this scenario. Please use Power BI REST APIs to get the valid URL". It doesn't seem to matter how we modify the URL, it won't load no matter what. When I remove the autoAuth QSP then it just shows a loading indicator forever.

I got the URL by going to the PowerBI report and selecting the Embed option and pasting that URL into my code. image

We already had code that was working with this report a few months back on this same package version but we had put it on the shelf and now when we came back it no longer is working despite not making any changes to it on our side. This leads me to believe it might be some kind of service side change that is causing the issue but if someone has other ideas on how to troubleshoot or things to try I would be open to any suggestions.

Embed snippet

import { PowerBIEmbed } from 'powerbi-client-react';

const reportUrl = 'https://<tenantDomain>.powerbi.com/reportEmbed?reportId=<reportId>&autoAuth=true&ctid=<tenantId>';
return (
    <div className={classNames.root}>
        <PowerBIEmbed
            embedConfig={{
                type: 'report',
                embedUrl: reportUrl,
            }}
        />
    </div>
);

Stats: Package version 1.3.5 (also tested with 1.4.0)

Screenshot image

may-hartov commented 1 year ago

This issue is not related to powerbi-client-react repository, seems to be a user error. The correct way to generate the embed url is not to have it static in the code, but use a REST API to GET the report using Power BI public REST APIs,. This is due to the fact the embed URL may change and contain some parameters that are required for the report render.

You can check out our developer samples to see how we fetch the embed URL

msnyder-msft commented 1 year ago

Thanks! The hard coded URL is a temporary thing just to see the report show up. But let me give that a try. Is it true that we need to pass the access token for the user even to show the report? In the past we were somehow getting away without having to do that but I see in the examples you shared they pass the token to the embed component so perhaps that is also causing this?

may-hartov commented 1 year ago

Yes, the token most be provided (access token or embed token)

NOELSAJO7 commented 7 months ago

Is there any way, I can embed the report without the access token ? as I want the report to be accessible to a particular group of people with autoAuth. Because having a bearer token will let anyone with it to access the report. Thank you

aicest commented 7 months ago

This problem occurs in powerbi-client@2.23.0 and can be mitigated by installing powerbi-client@2.22.4.

More: powerbi-client@2.23.0 has an allowedPowerBiHostsRegex regex that uses the g flag, which causes it to remember where the last successful match was, and therefore sometimes returns true and sometimes false.

tharakatk commented 7 months ago

This problem occurs in powerbi-client@2.23.0 and can be mitigated by installing powerbi-client@2.22.4.

More: powerbi-client@2.23.0 has an allowedPowerBiHostsRegex regex that uses the g flag, which causes it to remember where the last successful match was, and therefore sometimes returns true and sometimes false.

Thank you . Yes downgrading to powerbi-client@2.22.4 works for me.

Rohith-Rao commented 7 months ago

This problem occurs in powerbi-client@2.23.0 and can be mitigated by installing powerbi-client@2.22.4.

More: powerbi-client@2.23.0 has an allowedPowerBiHostsRegex regex that uses the g flag, which causes it to remember where the last successful match was, and therefore sometimes returns true and sometimes false.

thanks, this worked

NOELSAJO7 commented 7 months ago

This problem occurs in powerbi-client@2.23.0 and can be mitigated by installing powerbi-client@2.22.4.

More: powerbi-client@2.23.0 has an allowedPowerBiHostsRegex regex that uses the g flag, which causes it to remember where the last successful match was, and therefore sometimes returns true and sometimes false.

is there any solution for powerbi-client-react the library specifically for react

KotanaSai21 commented 7 months ago

The issue has been fixed with the new version release of powerbi-client v2.23.1 .

Install the latest version and let us know if you still face the same issue.

Removable commented 7 months ago

The issue has been fixed with the new version release of powerbi-client v2.23.1 .

Install the latest version and let us know if you still face the same issue.

It works for me! thx!

fadingNA commented 7 months ago

The issue has been fixed with the new version release of powerbi-client v2.23.1 .

Install the latest version and let us know if you still face the same issue.

2.23.1 worked for me too thanks!

burakgumusfb commented 7 months ago

I had same issue. Thanks for v.2.23.1 It worked for me too.

ciprian-dragomir commented 7 months ago

I had a different error message (Invalid embed URL detected. Either URL hostname or protocol are invalid. Please use Power BI REST APIs to get the valid URL), though looks like the same underlying issue. Confirming v2.23.1 fixed it for me as well. Thanks!

Removable commented 6 months ago

I am still facing this issue can someone help me with this? I am using v2.23.1 and migrated to react 18 Screenshot from 2024-04-12 13-08-09

Can you please show a screenshot of the dependencies part in your package.json file?

Removable commented 6 months ago

image

Hmm... it seems nothing special. Maybe you can try deleting the node modules folder and the package.lock.json file, then run npm install to reinstall all the packages. I don't know if it helps but have a try. 😃