Hi I am creating a service to upload csv of contacts to a contact list ,
public String uploadContactsCSV(){
try{
final RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.add(HttpHeaders.AUTHORIZATION,"Bearer " +genesysAuth.getToken());
headers.setContentType (MediaType.MULTIPART_FORM_DATA);
LinkedMultiValueMap<String, Object> body = new LinkedMultiValueMap<>();
// byte[] csv = CSVCLwriter.CSVwriter();
InputStream myInputStreamDocument = new ByteArrayInputStream(CSVCLwriter.CSVwriter());
body.add("id", "9e21a551-59bb-4e56-b2bc-2e0b65a0d071");
body.add("file", new MultipartInputStreamFileResource(myInputStreamDocument, "testingCSV"));
body.add("fileType", "contactlist");
body.add("contact-id-name", "CHD_CUST_EXTR_ID");
System.out.println(body);
HttpEntity<LinkedMultiValueMap<String, Object>> requestEntity = new HttpEntity<>(body, headers);
System.out.println(requestEntity);
ResponseEntity<Object> response = restTemplate.exchange("https://apps.mypurecloud.com/uploads/v2/contactlist", HttpMethod.POST, requestEntity, Object.class);
System.out.println(response.getStatusCode());
}catch (Exception e){
e.printStackTrace();
return e.getMessage();
}
return "testing....contacts added " ;
}
-------------------------------------------------------------------------------------------------------------------------------------------------------
<{id=[9e21a551-59bb-4e56-b2bc-2e0b65a0d071], file=[InputStream resource [resource loaded through InputStream]], fileType=[contactlist], contact-id-name=[CHD_CUST_EXTR_ID]},[Authorization:"Bearer HANDLE AUTH TOKENS AS PASSWORDS", Content-Type:"multipart/form-data"]>
org.springframework.web.client.HttpClientErrorException$Unauthorized: 401 : [no body]
at org.springframework.web.client.HttpClientErrorException.create(HttpClientErrorException.java:105)
at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:168)
at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:122)
at org.springframework.web.client.ResponseErrorHandler.handleError(ResponseErrorHandler.java:63)
at org.springframework.web.client.RestTemplate.handleResponse(RestTemplate.java:819)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:777)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:711)
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:602)
----------------------------------------------------------------------------------------------------------------------------------------------------
I found this forum response and decided to follow it but still cant get to upload the csv to the list I created Bad request Upload Contact Lists
I know 401 is unauthorized but I am authorized to created list and to add contact to a list but why is happening when I am trying to upload the csv