Forum Discussion

nilanjanpalMol's avatar
nilanjanpalMol
Frequent Visitor
4 years ago

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

  • 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?

    • nilanjanpalMol's avatar
      nilanjanpalMol
      Frequent 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.