Java - Add Factor on Registration Skip to main content
https://support.okta.com/help/answers?id=9062a000000qufiqac&refurl=http%3a%2f%2fsupport.okta.com%2fhelp%2fanswers
How satisfied are you with the Okta Help Center?
Thank you for your feedback!
How satisfied are you with the Okta Help Center?
1
2
3
4
5
Very Dissatisfied
Very satisfied
Enter content less than 200 characters.
Ask Search:
Flavel HeymanFlavel Heyman 

Java - Add Factor on Registration

We required the "Security Question" MFA and I was trying to write the code to add the factor but keep receiving an error message: 

HTTP -1, Okta E0000003 (The request body was not well-formed.), ErrorId oaed7Qo2BLCQkm8YzCb8tF5KQ

Code:

com.okta.sdk.resource.user.User newUser = UserBuilder.instance()<add_stuff_here>.setActive(false).buildAndCreate(oktaClient);

Iterator<Factor> factors = newUser.listSupportedFactors().iterator();
while (factors.hasNext()) {
  Factor factor = factors.next();

  if (factor instanceof SecurityQuestionFactor) {
    SecurityQuestionFactor sqf = (SecurityQuestionFactor) factor;
    SecurityQuestionFactorProfile profile = sqf.getProfile();
    profile.setQuestion("name_of_first_plush_toy");
    profile.setAnswer("Hardcoded");
    sqf.setProfile(profile);

    newUser.addFactor(sqf);
    newUser.activate(false);
}
I wasn't sure what part of the request body was not well-formed (newUser.addFactor(sqf); is the location of the exception)
Best Answer chosen by Flavel Heyman
Flavel HeymanFlavel Heyman
Nevermind, found out how to instantiate Factors:  oktaClient.instantiate(SecurityQuestionFactor.class);