The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
I have integrated powerbi import api with post operation in the spring boot application using RestTemplate
It failing with the 404 error while testing.
Below is my request endpoint, body and Error details.
Pls assist to fix the error.
Endpoint
--------
Request body
---------------
<{file=[file [C:\testing\test.pbix]]},[Authorization:"Bearer <token>", Content-Type:"multipart/form-data"]>
Error
-----------
org.springframework.web.client.HttpClientErrorException$NotFound: 404 Not Found on POST request for
"https://api.powerbi.com/v1.0/myorg/43948077-e943-4743-bf64-ff5ad19d51b2/imports": [no body]
<{file=[file [C:\testing\test.pbix]]},[Authorization:"Bearer <token>", Content-Type:"multipart/form-data"]>
Hi @naveenvnit ,
We’d like to follow up regarding the recent concern. Kindly confirm whether the issue has been resolved, or if further assistance is still required. We are available to support you and are committed to helping you reach a resolution.
Thank you for your patience and look forward to hearing from you.
Best Regards,
Chaithra E.
Hi @naveenvnit ,
Thank you for the update.
Power BI may redirect requests to a regional cluster e.g., wabi-west-us-redirect.analysis.windows.net. While your code attempts to follow this redirect manually, it's important to note that Spring’s RestTemplate does not automatically follow redirects for POST requests. Therefore, you should extract the redirected URL from the initial 307 Temporary Redirect response and use it as the actual import endpoint for subsequent requests.
The InvalidFileSizeError with a reported size of 9223372036854775807 indicates that the file size is not being correctly read. This issue often arises when using FileSystemResource. To avoid this, use ByteArrayResource instead, which ensures accurate file size detection and avoids compatibility issues with the Power BI API.
Do not manually set the Content-Type header to multipart/form-data. Doing so can interfere with the automatic generation of multipart boundaries, which are essential for properly formatting the request. Let RestTemplate handle this header internally when constructing the multipart request.
To isolate whether the issue lies within your code or the API itself, replicate the same request using Postman. Ensure you use the correct endpoint, headers, and file upload configuration. Additionally, enable detailed HTTP logging in your Spring Boot application to inspect the raw request being sent. This can help identify any misconfigurations in headers, body formatting, or endpoint construction.
Hope this helps.
Warm Regards,
Chaithra E
Hi @naveenvnit ,
We would like to confirm if you've successfully resolved this issue or if you need further help. If you still have any questions or need more support, please feel free to let us know. We are more than happy to continue to help you.
Thank you for your patience and look forward to hearing from you.
Best Regards,
Chaithra E.
Thanks for checking with me.
I'm still getting the error and But this time, I'm getting 307 error as the response with the header it redirected to the "https://wabi-west-us-redirect.analysis.windows.net/v1.0/myorg/groups/43948077-e943-4743-bf64-ff5ad19..."
also I have updated the code snippet below and Pls let me know if anything wrong with the code.
1st Rest call response
-----------------
<307 TEMPORARY_REDIRECT Temporary Redirect,[Content-Length:"0", Location:"https://wabi-west-us-redirect.analysis.windows.net/v1.0/myorg/groups/43948077-e943-4743-bf64-ff5ad19...", request-redirected:"true", home-cluster-uri:"https://wabi-west-us-redirect.analysis.windows.net/", x-ms-redirected-tenant-id:"be0f980b-dd99-4b19-bd7b-bc71a09b026c", Strict-Transport-Security:"max-age=31536000; includeSubDomains", X-Frame-Options:"deny", X-Content-Type-Options:"nosniff", Access-Control-Expose-Headers:"RequestId,Location", RequestId:"9034577d-6568-49c6-85c9-b0f1a7c456ac", Date:"Mon, 11 Aug 2025 15:13:03 GMT"]>
2nd Rest call response
--------------
I also tried to call the rest endpoint "https://api.powerbi.com/v1.0/myorg/groups/43948077-e943-4743-bf64-ff5ad19d51b2/imports?datasetDispla..." with the file as the body
org.springframework.web.client.HttpClientErrorException$BadRequest: 400 Bad Request on POST request for "https://wabi-west-us-redirect.analysis.windows.net/v1.0/myorg/groups/43948077-e943-4743-bf64-ff5ad19...": "{"error":{"code":"InvalidFileSizeError","pbi.error":{"code":"InvalidFileSizeError","parameters":{"FileSize":"9223372036854775807"},"details":[],"exceptionCulprit":1}}}"
Code
----------
String url = String.format(secretManagerEntity.getPowerBIEntraEndpoint() + "/groups/%s/imports", groupId);
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url)
.queryParam("datasetDisplayName", URLEncoder.encode(datasetName, "UTF-8"))
.queryParam("nameConflict", "CreateOrOverwrite")
.queryParam("PreferClientRouting", "true");
HttpHeaders headers = PowerbiServerAppUtils.getHttpHeader();
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
headers.put(HttpHeaders.CONTENT_TYPE, Arrays.asList(MediaType.MULTIPART_FORM_DATA_VALUE));
FileSystemResource resource = new FileSystemResource(pbixFile);
var body = new LinkedMultiValueMap<String, Object>();
body.add("file", resource);
HttpEntity entity = new HttpEntity<>(body
, headers);
ResponseEntity<String> response = restTemplate.postForEntity(restEndpoint, entity, String.class);
if(response.getStatusCode().is2xxSuccessful()){
logger.info("Report Import Submitted");
}
if (response.getStatusCode() == HttpStatus.TEMPORARY_REDIRECT) {
logger.info("Redirect URL: " + response.getHeaders().getLocation());
response = restTemplate.postForEntity(response.getHeaders().getLocation(), entity, String.class);
}
Hi @naveenvnit ,
Thank you for reaching out to Microsoft Community.
To resolve the 404 error you're encountering when using the Power BI Import API via a Spring Boot application, ensure that the workspace (group) ID used in the URL is valid, exists in your Power BI tenant, and is accessible with your bearer token.
If you're importing into "My Workspace," the URL should exclude the /groups/{groupId} segment entirely (i.e., use https://api.powerbi.com/v1.0/myorg/imports).
Your Azure AD token must have appropriate permissions such as Dataset.ReadWrite.All, Workspace.ReadWrite.All, or Tenant.ReadWrite.All to authorize the import operation.
Verify that the .pbix file is not corrupted and is accessible at the specified file path, and ensure that the request is formatted as a multipart/form-data POST request with the file included under the field name file. Log and inspect the complete request URL and body before execution to catch any issues with path variables or headers.
To further isolate whether the issue is in your code or the API itself, test the same import request using Postman with the same URL, headers, and file. Additionally, enable detailed HTTP logging in your Spring Boot application to view the actual HTTP request being sent, which can reveal any misconfigurations in headers or body formatting.
Hope this helps.
Warm Regards.
Chaithra E.