The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredCompete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.
While Using Post Import In Group API, encounter the following error:
400 Bad Request from POST https://api.powerbi.com/v1.0/myorg/groups/{group_id}/imports?datasetDisplayName={datasetDisplayName}...
The pbix file size in question is approximately 2MB.
NOTE: Same API works fine when publishing a 2MB Excel file.
Please find the below code in Java using reactive Web Client
public Mono<String> publishPowerBIReport(String fileName, FilePart fileP) throws Exception {
String filename = fileP.filename();
Path tempFilePath = Paths.get(System.getProperty("java.io.tmpdir"), filename);
File file = tempFilePath.toFile();
FileSystemResource fileSystemResource = new FileSystemResource(file);
String boundary = "---------------------------" + Long.toHexString(System.currentTimeMillis());
MultipartBodyBuilder builder = new MultipartBodyBuilder();
builder.part("file", fileSystemResource)
.header(HttpHeaders.CONTENT_DISPOSITION, "form-data; name=\"file\"; filename=\""+filename+"\";")
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_OCTET_STREAM_VALUE);
MultiValueMap<String, HttpEntity<?>> multipartData = builder.build();
webClientBuild();
String token = getAccessToken();
return webClient.post().uri(uriBuilder -> uriBuilder
.path(RELATIVE_URL)
.queryParam("datasetDisplayName", fileName)
.queryParam("subfolderId", SUB_FOLDER_ID)
.queryParam("nameConflict", "Overwrite")
.build())
.body(BodyInserters.fromMultipartData(multipartData))
.header(HttpHeaders.AUTHORIZATION, "Bearer " + token)
.header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA_VALUE+"; boundary=" + boundary)
.retrieve()
.bodyToMono(String.class)
.doOnSuccess(
response -> System.out.println("File uploaded successfully: " + response + "***END****")
)
.doOnError(WebClientResponseException.class, error ->
System.err.println("Error uploading file: --->" + "Error Message :: " + error.getMessage() + " Error Response :: " + error.getResponseBodyAsString() + "***END****")
);
}
We face the same problem. Did you manage to solve this ?
Hi @Anonymous , Thank you for your response.
I had tested same file using Postman and powershell, it is working fine. So looks like it's not the case of file corruption.
Also same upload code is working fine if I upload an Excel file instead of power bi with same size. As mention in PowerBi documentation that
Supported content:
Imports - Post Import In Group - REST API (Power BI Power BI REST APIs) | Microsoft Learn
I found one difference while testing with Postman is that, postman header contain Content-Length: parameter and its calculate length at run time. In postman console I can see the calculated size of Content-Length, But when I tried to pass the same content-length using my code, its throws a different exception mention below
{
"code": "InputStreamIncorrectLengthException",
"message": "The length of the file input stream does not match the provided length. Expected: '1177397', Actual (approximate): '1177398.'"
}
I am not sure at this moment, that Web Client in java calculate Content-Length internaly or not but looks like PowerBI Post import in gropu API required content-length too in header. Not sure how to resolve this issue.
I went through similier kind of issue discussion in below Post
https://community.fabric.microsoft.com/t5/Developer/quot-InvalidFileSizeError-quot-when-upload-for-temporary-storage/m-p/3231632#M42636
Hi @Anonymous ,
Based on the error message, ‘FileSize is recognized as 9223372036854775807’. This indicates that the Power BI API encountered an issue when parsing the file size. It could be related to the method of file upload, or it may be caused by file corruption.
I suggest that you consider using Postman or PowerShell to try uploading your PBIX file to rule out any issues related to the file itself. If the file uploads successfully, it is likely that the problem lies within the Java code.
Here’s the PowerShell script for uploading a PBIX file to a Power BI workspace:
# Install required module (if not already installed)
Install-Module -Name MicrosoftPowerBIMgmt
# Sign in to Power BI (this will open a login window)
Connect-PowerBIServiceAccount
#Import
New-PowerBIReport -Path "C:\XX\XXX\XX\XXX.pbix" -Name "0902" -WorkspaceId "8xxxxx5cd9-8643-4664-a87c-7b6097xxxxxx"
Best Regards,
Bof
I think for rdl files this approach it doesn't work and I really don't understand why!!!
User | Count |
---|---|
39 | |
15 | |
13 | |
11 | |
8 |
User | Count |
---|---|
49 | |
43 | |
23 | |
19 | |
18 |