Adding a header to a web API request in the data sources section of a report in PBI Report Server - powerbi

I have created a report using power bi desktop (Version January 2021). In order to get the data for this report, I connect to a web API using the provided API key in the header part of the request:
This part works fine and I get the necessary data to work on the Power BI desktop.
When I publish the created report to a Power BI Report Server, as you can see in the following image, there is no way to add the header data which in this case is mandatory to authenticate:
The Authentication part in the Credential section in the above image does not support adding headers data and only accepts Anonymous, Basic, and Windows authentication which are not applicable here (The test fails).
As the data in my report changes regularly and I need to schedule an automatic refresh, the Report Server has to connect to the Web API at the scheduled times in order to get the latest version of the data.
I would appreciate it if you could help me to solve the encountered problem. Regards

The access key should be part of the query options and in PowerQuery you should have something like
Source = Csv.Document(
Web.Contents(
"http://example.com",
[
RelativePath = "api",
Query =
[
api-key = "s4fad456df"
]
]
),
),
The authentication to the web data source is always Anonymous in Power BI.
https://learn.microsoft.com/en-us/powerquery-m/web-contents

Related

any Rest APIs to create a report in powerbi service?

i have searched official powerbi docs thoroughly.
There are APIs for creating datasets, updating them and for deleting them.
Additionally, there are APIs to clone, update and delete a report.
But after searching a lot, I have not been able to find anything that can help me in creation of a fresh new (visual) report through API?
PS: actually I want to create a visual (not paginated) report without manually going to powerbi desktop or service. I just want to do it with the help of a powerbi rest API.
So is there anyway we can create a new report from existing dataset w/ rest API?
Also, if not possible with rest apis, could this may be possible with powerbi-embedding?
Yes, it is possible.
First, you need to generate an embed token for report creation from a dataset present in your PBI Service. It can be done by making a POST request to the API from backend.
After that, you can create a new report from that dataset. (Using createReport method in your frontend)
example:
let embedCreateConfiguration = {
tokenType: tokenType,
accessToken: accessToken,
embedUrl: embedURL,
datasetId: datasetId,
settings: settings, //optional
theme: theme, // optional
};
// Grab the reference to the div HTML element that will host the report
let embedContainer = $('#embedContainer')[0];
// Create report
let report = powerbi.createReport(embedContainer, embedCreateConfiguration);
References:
Create, edit, and save an embedded report | Microsoft Learn
Embed Token - Reports GenerateTokenForCreateInGroup - REST API (Power BI Power BI REST APIs) | Microsoft Learn

Power BI - Difference between Publish to Web and Website (Portal)

I want to know the difference in the following 2 options in Power BI Service -> File -> Embed Report:
Website or Portal
Publish to Web (public)
My observation was that you can use Report Filters in Website or Portal option but Report Filters are disabled in Publish to Web option.
Can someone please answer my following queries:
When should we use each of the 2 options?
Which option needs Power BI Embedded Tokens and Capacity to use in production environment?
Can users use Filtering on the report in both the 2 options?
Thanks!
Gagan
Please find the answer below:
1.Difference between Publish to Web and Publish to Website
Publish to Web:
Report will be public
No need to Login (Anyone with the link can view the report)
With the Power BI Publish to web option :
a. You can easily embed interactive Power BI content in blog posts, websites, emails, or social media.
b. You can also easily edit, update, refresh or stop sharing your published visuals.
Publish to Website:
Report will be private
Need to Login first (Unauthorized personal can’t be able to view the report)
With the Power BI Publish to website option :
a. User who has access to that workspace can see the report.
b. User who is member of your organization can see report from that workspace.
2.You don't need the Tokens and Capacity to publish the reports to web or website.
3.Filtering with Publish to Website and Publish to Web
With Publish to Website you can use filtering.
With Publish to Web to use the filtering on the report, you need to have the Power BI Pro License.
Publish to web does not allow display of the filter pane and tabs - at least as for now according to the Microsoft - see this link and the section called "Considerations and Limitations": https://learn.microsoft.com/en-us/power-bi/create-reports/power-bi-report-filter. So if you have filters in the filter pane you would have to move them over to the main content of the report - not ideal if users are already used to using filters on the filter pane.
Publish to website or portal will just give you an iframe with a private URL and when users load the web page they will have to authenticate.
In order to embed and authenticate on behalf of all the users you will need a token. One way to do this is using principal service account - this way you won't be supplying any user account credentials. This workflow is well documented and you can even download a test application with working code where you would need to supply your values such as workspace id, report id, tenant id, application id and finally application secret. Get started with token authentication using this link: https://learn.microsoft.com/en-us/power-bi/developer/embedded/embed-tokens. Double check token expire date and set it appropriately.

Power BI embedding issues

I'm doing some R&D with a power BI Visual Studio solution and I'm struggling to programmatically embed content. I have the Power BI Pro trial.
From the Embed Setup webpage, I created an application ("User owns Data" with sample data) and downloaded the sample VS solution which comes configured with the GUIDs for the app that was just created. The app appears in my Power BI web interface and when I run the VS web app, I get three buttons (embed report | embed dashboard | embed tile). This works - I can view the embedded report.
My problem is when I install an app using the Power BI interface and then try to run my VS project using the appId of the app I just installed. For example - I installed the Github app and chose to use sample data. If I plug in the appId, workspace Id and report Id into my VS project, I get the following message when I run it and click the "Embed Report" button
AADSTS700016: Application with identifier '5c7d26d1-006d-43ac-9eb7-6aa3e1f6b364' was not found in the directory 'foo.onmicrosoft.com'. This can happen if the application has not been installed by the administrator of the tenant or consented to by any user in the tenant. You may have sent your authentication request to the wrong tenant.
Trace ID: e77376aa-b7ca-4c09-9184-31f96eea9800
Correlation ID: d42a0b9c-c93d-4601-87d6-05d9cca70e0d
Timestamp: 2019-06-04 15:59:58Z
Why is it that an app I created using the "Embed Setup" page works, but a different app's Ids fail with that error?
I am using the same login credentials in the VS project as I am logging into the Power BI website with, as well as when I created an app with the "Embed Setup" page.
Could it be that it is looking for an app that is registered in my Azure portal under the Active directory > App Registrations? If so, why does the other Power BI app work (Embed Setup route)?
When I tested creating an app using "App Owns Data", the application was registered in my Azure AD
As a side note - is there an easy way to get app, workspace and report Ids for an app? AppId is easy enough to grab from the URL, but workspace Id never seems to appear
UPDATE
After using the 'onboarding embed tool' as suggested #Andrey, I do see the application registered in Azure, but if I replace the applicationId web.config key with the Id of the Azure application, I get a different error message (below). I'm confident that the applicationId int the web.config of the generated project is specifically the (Power BI) App Id and not the Azure Application Id (not confusing at all, Microsoft!). Using the Azure Application Id, I get the following error:
Error
AADSTS7000218: The request body must contain the following parameter: 'client_assertion' or 'client_secret'.
Trace ID: 5e8391c2-4681-4c8e-9294-a99fd56dbb00
Correlation ID: 10d48927-d5ec-45bd-a5b3-e9c1e147f97c
Timestamp: 2019-06-05 15:29:44Z
I feel like there is documentation that I need but can't find. I've created the Application that appears in Azure (I had done this before, but could not find any connection between this application and my PowerBI page). I've created apps, workspaces, and reports in Power BI. All I want to do is use the .Net SDK to pull in visualisations from a specific Power BI installation i.e. insert a visualisation of a client's data onto their website.
I'll keep digging and update when I find a solution
You are mixing two different "app ids". First app ID (also called client ID) is the one that you are registering in the onboarding embed tool (https://dev.powerbi.com/apps), which I believe is what you called "Embed Setup" (or embed setup is something on top of that). This app registrations will be visible in Azure AD after that. The other "app" that you mention is "Power BI App", i.e. a collection of reports that are packed together in an app. These two "apps" are completely different and you can't use the ID of the later one when embedding Power BI elements.
When you open a report saved in a workspace, the URL will be in the following format:
https://app.powerbi.com/groups/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/reports/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/ReportSection
First guid (the x-es after groups) is the workspace ID (also called group ID). The later one (after reports) is the report ID. There is no "workspace and report Ids for an app", because your app (the one that you registered and is visible in Azure AD) can access various reports in various workspaces. The reports packed in a "Power BI app" should be embedded from their original workspace, not from the app.
I eventually found the solution I was looking for. Essentially you use the PowerBI C# SDK to authenticate and return your PowerBI data - like collections of reports, which you can then embed using the JS API
private async Task<AuthenticationResult> DoAuthentication()
{
AuthenticationResult authenticationResult = null;
if (AuthenticationType.Equals("MasterUser"))
{
var authenticationContext = new AuthenticationContext(AuthorityUrl);
// Authentication using master user credentials
var credential = new UserPasswordCredential(Username, Password);
authenticationResult = authenticationContext.AcquireTokenAsync(ResourceUrl, ApplicationId, credential).Result;
}
else
{
// For app only authentication, we need the specific tenant id in the authority url
var tenantSpecificURL = AuthorityUrl.Replace("common", Tenant);
var authenticationContext = new AuthenticationContext(tenantSpecificURL);
// Authentication using app credentials
var credential = new ClientCredential(ApplicationId, ApplicationSecret);
authenticationResult = await authenticationContext.AcquireTokenAsync(ResourceUrl, credential);
}
return authenticationResult;
}
then, to get a list of reports
public IList<Report> GetReportsByGroup(string groupId)
{
if (_reports == null)
{
var Client = new PowerBIClient(new Uri(ApiUrl), new TokenCredentials(AccessToken, "Bearer"));
_reports = Client.Reports.GetReportsInGroup(groupId).Value;
}
return _reports;
}

Power BI Embedding

I'm using Power BI REST API's to integrate or embed the reports created in Power BI. By using these API's i'm getting Access token, Embed token, Report Id, Data-set Id and Embed URL also but when i embed my report using J query Ajax then it gives me the pref-light error. So, please let me know how to solve this error. In addition of this i have Power BI Pro account. Below are the API's and screenshot of error.
https://login.microsoftonline.com/common/oauth2/token
https://api.powerbi.com/v1.0/myorg/groups/976sdsdf-c82e-4217-9f74-3c50e694fe6f/reports
https://api.powerbi.com/v1.0/myorg/groups/9765dc8f-c82e-4217-9f74-3c50e6qwwq6f/reports/32fwdqwa-e31b-4676-b598-7268baa5be75/GenerateToken
See if relevant
Got 400 error for pre-flight options CORS token request from OWIN-based WebAPI
Also, can you maybe check what is the response itself that is returned? what is there besides the 400? maybe some message?

Power BI reply URL does not match reply URLs configured for the application

There are many similar questions asked in Stack Overflow but so far as I'm aware, none provide the information that solves this issue.
Goal
Anyone in my organization (but not outside of it) must be able to view a Power BI report. Not all users in my organization have Power BI Pro accounts, so sharing the report in SharePoint is not an option, as I understand it.
Background
In past years I embedded a Power BI report in an Azure web app using a Power BI workspace collection and secured it with Azure Active Directory. This worked fine. Recently Microsoft retired Power BI workspace collections. I need to find another way to embed the report in an Azure web app.
Failed attempts
I tried using Microsoft's onboarding/migration tool but it was too confusing. (I am not a professional developer.) Sample Power BI and Azure code provided by Microsoft on GitHub are also confusing to me.
An Angular solution on Medium successfully walked me through the steps to accomplish my goal, but placed the responsibility of creating a solution that can fetch access tokens on the reader, a skill I don't have.
A Visual Studio solution in GitHub embeds a report in an Azure web app if the following are provided:
"AzureAd": {
"Instance": "https://login.microsoftonline.com/common",
"ClientId": "redacted",
"ClientSecret": "redacted",
"CallbackPath": "/signin-oidc",
"Resource": "https://analysis.windows.net/powerbi/api",
"EmbedUrlBase": "https://app.powerbi.com/*"
Status
I collected the ClientId from Azure > Azure Active Directory > Application ID.
I collected the ClientSecret from Azure > Azure Active Directory > Keys > added key called "secret", saved, and copied the value.
Reply URLs I've tried (based on suggestions on the web) include:
https://website.azurewebsites.net/signin-oidc
https://app.powerbi.com/embedsetup/SignInRedirect (which I believe was added when I attempted to use the onboarding/migration tool)
http://localhost/* (http://localhost:44341/* works when built locally)
In addition, I have a Report ID, Workspace ID, Group ID from the onboarding/migration tool.
Problem
I continue to encounter the AADSTS50011: The reply url specified in the request does not match the reply urls configured for the application error. (No reply URL is specified in the error message.)
Question
How do I successfully provide a reply URL and callback path? An answer that would be helpful would direct me how to find exactly what to type in.
I can provide additional information if needed. Thank you for any advice.
You have no value specified for the Reply URL in your config. This needs to be there as well. In your App Registration and in your config you need to list the same URL as your Reply URL. This is where you want the user to be directed after he or she has signed in. Try listing your main homepage URL (https://hccanalytics.azurewebsites.net/) in both.
See my blog post and video to see if this helps.