Forum Discussion
404 error client error - post /imports power bi api
- 1 year ago
Hi Anonymous ,
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 Anonymous ,
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.
- Anonymous1 year agoNot applicable
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-ff5ad19d51b2/imports?datasetDisplayName=test&nameConflict=CreateOrOverwrite&PreferClientRouting=true"
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-ff5ad19d51b2/imports?datasetDisplayName=test&nameConflict=CreateOrOverwrite&PreferClientRouting=true", 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?datasetDisplayName=test&nameConflict=CreateOrOverwrite&PreferClientRouting=true" 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-ff5ad19d51b2/imports": "{"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);
}