I was just trying to create a user with spring resttemplate using code like below but I am getting 400 response. I can use the get method to retrieve the users so I’m not sure what I need to change to create a user. Let me know what I am doing wrong here.
RestTemplate restTemplate = getRestTemplate();//new RestTemplate();
URIBuilder builder = new URIBuilder();
builder.setScheme("https")
.setHost("mydevhost-admin.oktapreview.com")
.setPath("/api/v1/users")
.setParameter("activate", "true");
java.net.URI url = builder.build();
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.set("Accept","application/json");
headers.set("Authorization", "SSWS mytokenvalue");
OKTAUser oktaUser = new OKTAUser();
Profile profile = new Profile();
profile.setEmail("test@test.com");
profile.setFirstName("First");
profile.setLastName("Last");
profile.setLogin("test@test.com");
profile.setMobilePhone("111-111-1111");
Credentials credentials = new Credentials();
Password password = new Password();
password.setValue("abcdefghi");
credentials.setPassword(password);
oktaUser.setCredentials(credentials);
oktaUser.setProfile(profile);
JSONObject jsonObj = new JSONObject( oktaUser );
HttpEntity<String> requestEntity = new HttpEntity<String>(jsonObj.toString(), headers);
ResponseEntity<String> uri = restTemplate.exchange(url, HttpMethod.POST, requestEntity, String.class);