Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
hadesflames
New Member

Report Import REST API 500 Error

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.

2 REPLIES 2
Jayendran
Solution Sage
Solution Sage

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);
      }
    }

 

Reference: https://github.com/CriticalPathTraining/PbixInstallerForPowerBI/blob/master/PbixInstallerForPowerBI/...

Code is in TypeScript (NodeJS) not C#.

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.