Quantcast
Channel: All Developer posts
Viewing all articles
Browse latest Browse all 48312

Re: Importing an Excel file using the Import API returns a 400 Bad Request error

$
0
0

simplest case is using curl

 

 

curl -v --header "Authorization: Bearer <auth-token removed>" -F "upload=@/Users/me/Documents/workspace/test_excel2.xlsx" https://api.powerbi.com/v1.0/myorg/imports

 

More complicated java snippet

 

 

org.apache.commons.httpclient.methods.PostMethod method_FileSend_1 = new org.apache.commons.httpclient.methods.PostMethod(
"https://api.powerbi.com/v1.0/myorg/imports");

org.apache.commons.httpclient.methods.multipart.FilePart file_1_FileSend_1 = new org.apache.commons.httpclient.methods.multipart.FilePart(
"TEST_DATASET",
new java.io.File(
"/Users/me/Documents/devl/workspace/test_excel2.xlsx"),
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
"ISO-8859-1");

org.apache.commons.httpclient.methods.multipart.Part[] parts_FileSend_1 = new org.apache.commons.httpclient.methods.multipart.Part[] { file_1_FileSend_1, };
method_FileSend_1
.setRequestEntity(new org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity(
parts_FileSend_1, method_FileSend_1
.getParams()));

method_FileSend_1.addRequestHeader("Authorization", "Bearer "
+ context.access_token);

method_FileSend_1.addRequestHeader("datasetDisplayName",
"TEST_EXCEL_DATASET");

method_FileSend_1.addRequestHeader("nameConflict",
"Overwrite");

boolean isContinue_FileSend_1 = true;
int status_FileSend_1;
String finalURL_FileSend_1 = "https://api.powerbi.com/v1.0/myorg/imports";

try {

status_FileSend_1 = client_FileSend_1
.executeMethod(method_FileSend_1);

if (status_FileSend_1 != org.apache.commons.httpclient.HttpStatus.SC_OK) {
throw new java.lang.Exception("Method failed: "
+ method_FileSend_1.getStatusLine());
}

} catch (java.lang.Exception e) {

throw (e);

}

if (isContinue_FileSend_1) {

System.out.println("Status Line: "
+ method_FileSend_1.getStatusLine());
System.out.println("*** Response Header ***");
org.apache.commons.httpclient.Header[] responseHeaders_FileSend_1 = method_FileSend_1
.getResponseHeaders();

for (int i = 0; i < responseHeaders_FileSend_1.length; i++) {
System.out.print(responseHeaders_FileSend_1[i]);
}


Viewing all articles
Browse latest Browse all 48312

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>