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 ,
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.