Forum Discussion
Unable to upload Excel data via API
Hello everybody,
I am trying to programatically upload an Excel file (could also be a JSON file) to a workspace using the API but I can't seem to make it quite work.
I am using the endpoint as specified at https://docs.microsoft.com/en-us/rest/api/power-bi/imports/post-import-in-group where the phrasing leads me to believe it should be possible to import Excel files this way.
Sample C# code used :
public bool ImportExcelFileToWorkspace(string filePath, string filename, string displayName)
{
var req = new HttpRequestMessage(HttpMethod.Post, $"https://api.powerbi.com/v1.0/myorg/groups/{Context.GroupId}/imports?datasetDisplayName={displayName}");
var content = new MultipartFormDataContent();
Stream fileStream = File.OpenRead(filePath);
content.Add(new StreamContent(fileStream), displayName, filename);
req.Content = content;
Credentials.ProcessHttpRequestAsync(req, CancellationToken.None);
var message = Client.HttpClient.Send(req);
return message.IsSuccessStatusCode;
}
I am using a class with a Credentials fields that uses the .NET API Connector and auth is fine.
Both the filename and displayname variables feature the file extension.
Using this method, I am being return an error 400 Bad Request with detail "ExcelWorkbookHasNoDataException" which is false.
Has anybody successfully used this endpoint like I am intending ? Any insight as to what I might be doing wrong ?
Thank you all in advance !
Hi risDS ,
Quick solution
- Edit your workbook in Excel.
- Select the range of cells that contain your data. The first row should contain your column headers (the column names).
- Press Ctrl + T to create a table.
- Save your workbook.
- Return to Power BI and import your workbook again
You need create a data model in your excel when you want to upload excel to power bi serive.
For more details, you can refer this link.
Error: We couldn't find any data in your Excel workbook - Power BI | Microsoft Docs
Best Regards
Community Support Team _ chenwu zhu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
1 Reply
- v-chenwuz-msftCommunity Support
Hi risDS ,
Quick solution
- Edit your workbook in Excel.
- Select the range of cells that contain your data. The first row should contain your column headers (the column names).
- Press Ctrl + T to create a table.
- Save your workbook.
- Return to Power BI and import your workbook again
You need create a data model in your excel when you want to upload excel to power bi serive.
For more details, you can refer this link.
Error: We couldn't find any data in your Excel workbook - Power BI | Microsoft Docs
Best Regards
Community Support Team _ chenwu zhu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.