Hi, how can I upload a csv to a contactlist with java?
try {
final RestTemplate restTemplate = utils.createRestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.add(AUTHORIZATION, "Bearer " + accessToken);
MultiValueMap<String, Object> body = new LinkedMultiValueMap<>();
body.add("id", "3e4465f8");
body.add("file", sfos.read());
body.add("fileType", "contactlist");
body.add("contact-id-name", "PhoneId_1");
HttpEntity requestEntity = new HttpEntity<>(body, headers);
ResponseEntity response = restTemplate.exchange("https://apps.mypurecloud.com/uploads/v2/contactlist", HttpMethod.POST, requestEntity, Object.class);
System.out.println(response);
} catch (Exception e) {
e.printStackTrace();
throw new ServiceException(this.getClass().getName(), ERROR_SERVICE_API_PURECLOUD, e);
}
-> Error Bad Request 400
another way i try...
public class UploadContact {
private String id;
private int file;
private String fileType;
@JsonProperty("contact-id-name")
private String contactIdName;
...........
try {
final RestTemplate restTemplate = utils.createRestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.add(AUTHORIZATION, "Bearer " + accessToken);
UploadContact body = new UploadContact();
body.setId("3e4465f8");
body.setFile(sfos.read());
body.setFileType("contactlist");
body.setContactIdName("PhoneId_1");
HttpEntity requestEntity = new HttpEntity<>(body, headers);
ResponseEntity response = restTemplate.exchange("https://apps.mypurecloud.com/uploads/v2/contactlist", HttpMethod.POST, requestEntity, Object.class);
System.out.println(response);
} catch (Exception e) {
e.printStackTrace();
throw new ServiceException(this.getClass().getName(), ERROR_SERVICE_API_PURECLOUD, e);
}
-> Error Bad Request 400
can you help me?