Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! It's time to submit your entry. Live now!
Trying to upload .pbix files through the
`/v1.0/myorg/groups/{groupId}/imports`
API endpoint, and getting a 500 error returned.
status: 500,
statusText: 'Internal Server Error',
headers: {
'content-length': '0',
'strict-transport-security': 'max-age=31536000; includeSubDomains',
'x-frame-options': 'deny',
'x-content-type-options': 'nosniff',
'access-control-expose-headers': 'RequestId',
'request-redirected': 'true',
Here's the code snippet I'm using to make the request:
static async uploadReportToGroup(groupId: string, reportName: string, filePath: string): Promise<AxiosResponse | undefined>{
const accessToken = await PowerBIController.getAccessToken();
if(accessToken === '') {
return new Promise<undefined>((resolve: any, reject: any) => resolve(null));
}
const requestURL = (process.env.MS_API_URL as string) + 'groups/' + groupId + '/imports?datasetDisplayName=' + reportName + '&nameConflict=Overwrite';
const options = {
headers: {
Authorization: 'Bearer ' + accessToken,
'Content-Type': 'multipart/form-data',
'Content-Length': fs.statSync(filePath).size
},
httpAgent: new http.Agent({ keepAlive: true }),
httpsAgent: new https.Agent({ keepAlive: true })
};
const formData: FormData = new FormData();
formData.append('file', fs.createReadStream(filePath), { contentType: 'application/octet-stream' });
return axios.post(requestURL, formData, options);
}
You can assume that the AccessToken I'm retrieving is valid, as it works with other endpoints.
Hi @hadesflames ,
Can you try the below code
public static void ImportPBIX(string pbixFilePath, string importName) {
// delete exisitng import of the same name if on exists
DeleteImport(importName);
// create REST URL with import name in quer string
string restUrlImportPbix = ProgramConstants.PowerBiServiceRootUrl + "imports?datasetDisplayName=" + importName;
// load PBIX file into StreamContent object
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;
// check for success
if (response.StatusCode.ToString().Equals("Accepted")) {
Console.WriteLine("Import process complete: " + response.Content.ReadAsStringAsync().Result);
}
}
Code is in TypeScript (NodeJS) not C#.
The Power BI Data Visualization World Championships is back! It's time to submit your entry.
| User | Count |
|---|---|
| 4 | |
| 3 | |
| 2 | |
| 2 | |
| 1 |
| User | Count |
|---|---|
| 5 | |
| 5 | |
| 4 | |
| 4 | |
| 3 |