Okta User create issue

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);

What is the contents of the 400 response you receive? There is most likely some extra error information in there.

Can you use a tool like Charles or Fiddler to see the raw request and response on the wire?

I solved this but I’m not sure which of the variables were the problem. I removed -admin from the url and just added a more complex password than the generic one in my post. I’m sure this was syntax related so at least I was able to get the sample working so I think I’m good now.

That’ll do it! :slight_smile:

Glad you got it working. Let us know if you have any other issues.