I'm currently integrating Walmart into our application and I'm trying to post an Item Feed through the API method. I've already succeeded in posting a feed from the ARC tool, so I already know how to model the post request for it, my only problem is that I'm having difficulties in using it in my code, while using the Resttemplate.
Below is the request (from ARC - Chrome) that succeeded to post my item (I can see them in my Walmart Seller console) and the Java code for it (trimmed the credentials for security reason):
Obs: The signature and the other fields used in the Java code for the requests are correctly generated, because I used them in my request from ARC as well, so there's no issue in the headers' values, but in how I'm trying to set the file in the body request, as far as I can tell:
And the code for generating the headers and sending the post request with Resttemplate: ..............................
headers = new HttpHeaders();
headers.set("WM_SVC.NAME", "Walmart Marketplace");
headers.set("WM_QOS.CORRELATION_ID", "123456abcdef");
headers.set("WM_SEC.TIMESTAMP", timestamp);
headers.set("WM_SEC.AUTH_SIGNATURE", signatureString);
headers.set("WM_CONSUMER.ID", "my-consumer-id-cut-for-security-reasons");
headers.set("WM_CONSUMER.CHANNEL.TYPE", "my-channel-type");
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
headers.setAccept(Arrays.asList(MediaType.APPLICATION_XML));
headers.set("Host", "https://marketplace.walmartapis.com");
..............................
File file = new File("C:\\walmartfeed.xml");
DiskFileItem fileItem = new DiskFileItem("file", "text/xml", false, file.getName(), (int) file.length(), file.getParentFile());
fileItem.getOutputStream();
MultipartFile multipartFile = new CommonsMultipartFile(fileItem);
MultiValueMap<String, Object> parts =
new LinkedMultiValueMap<String, Object>();
parts.add("file", new ByteArrayResource(multipartFile.getBytes()));
HttpEntity<MultiValueMap<String, Object>> request = new HttpEntity<>(parts, headers);
restTemplate.getMessageConverters().add(new FormHttpMessageConverter());
restTemplate.getMessageConverters().add(new ByteArrayHttpMessageConverter());
restTemplate.getMessageConverters().add(new MultipartAwareFormHttpMessageConverter());
ResponseEntity<FeedAcknowledgement> response = restTemplate.exchange("https://marketplace.walmartapis.com/v3/feeds?feedType=item", org.springframework.http.HttpMethod.POST, request, FeedAcknowledgement.class);
I am receiving a 400 status code saying it's a bad request. Did you manage to post feeds for Walmart or is there any other way to use Resttemplate to post multipart/form-data / files ?
Thanks