Forum Discussion
Dataset credential is missing while publishing using Rest Api for report based on SharePoint Excel
I am trying to publish a Power BI report. It's underlining dataset is an excel file and that file is in SharePoint.
I am using service principal to authenticate Power BI service.
I am using below code to publish the report.
***************************************************************************
restUrlImportPbix = "https://api.powerbi.com/v1.0/myorg/groups/" + workspace + "/imports?datasetDisplayName=" + importName + "&nameConflict=Overwrite";
var pbixBodyContent = new StreamContent(File.Open(pbixFilePath, FileMode.Open));
// add headers for request bod content
pbixBodyContent.Headers.Add("Content-Type", "application/octet-stream");
pbixBodyContent.Headers.Add("Content-Disposition",
@"form-data; name=""file""; filename=""" + pbixFilePath + @"""");
// load PBIX content into body using multi-part form data
MultipartFormDataContent requestBody = new MultipartFormDataContent(Guid.NewGuid().ToString());
requestBody.Add(pbixBodyContent);
// create and configure HttpClient
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Add("Accept", "application/json");
client.DefaultRequestHeaders.Add("Authorization", "Bearer " + AccessToken);
// post request
var response = client.PostAsync(restUrlImportPbix, requestBody).Result;
***************************************************************************
Report is published successfully. But, underlining data source is missing the credential. As a result, dataset is not being refreshed unless credential is set manually from Power BI service.
As pre requirement, manually access to the workspace is restricted.
But while uploading a report based on Azure Sql DB, dataset is not losing the credential.
I am searching for a solution, if we can keep the credential during publish report.
7 Replies
- lbendlinSuper User
This reads like buzzword bingo - "Excel and Sharepoint and Service Principal". I think you picked a rather very complex scenario here. Please clarify if this is SPO, and if a gateway is involved.
Why would they restrict manual access to the workspaces for workspace administrators or developers?
- nilanjanpalMolFrequent Visitor
We have a portal. We are showing Power BI report through that portal (Embedding Power BI report).
As per the requirement, user is developing Power BI reports and publishing the reports through that portal. We are using Power BI rest api for publishing the report. Currently all the reports based on Azure SQL DB. Means user's are connecting Azure SQL DB, designing the report and publishing the same using our portal. So, far it is working properly.
There is no manual intervention. So, access to the Power BI service workspace is not possible.
Recently, we get a new requirement where user will design report based on excel file from SharePoint. During development we stuck of with above problem.
I don't know whether gateway is involved or not.- AnonymousNot applicable
HI nilanjanpalMol,
Can you please share some more details about your report settings? (e.g. data connector type, query table operation steps, data source credentials that you configured) They should help us clarify your scenarios.
How to Get Your Question Answered Quickly
In addition, you can also take a look at the following link to work with SharePoint files with a web connector, they can be refreshed with 'onedrive refresh' and not required to manage with data gateway.
Use OneDrive for Business links in Power BI Desktop - Power BI | Microsoft Docs
Regards,
Xiaoxin Sheng