Is there a way to change the attributes for a user programmatically using the okta sdk?

I need to update the Username user.login attribute to change the format restrictions to None and also add a new attribute of the format string array.

I have found out that there is a way from the UI, but I would like to do this from the code, using the okta java sdk or if that is not possible, then using the REST endpoint.

Is it possible? How would I go about it?

Thanks,
Aru

This blog post shows you how to use the Java SDK to get/set a custom attribute. Hope it helps!

Thanks Matt. That example shows how to get / set the values.

What I want to do is to define or change the properties of the User attributes.

Can I do that using the programmatic approach?

Aru

I don’t think you can define new attributes with the Java SDK. If you’d like to see this feature, please enter an issue for the project on GitHub.

Matt Raible

https://twitter.com/mraible

https://developer.okta.com/blog

Thanks Matt. Created an issue on Project’s Gitbub

One other tip: You can call arbitrary API endpoints from the SDK that aren’t explicitly supported (yet). Check out this part of the docs: https://github.com/okta/okta-sdk-java/blob/master/README.md#call-other-api-endpoints

To create a new user profile attribute, you’d model out the user profile custom subschema as documented here: https://developer.okta.com/docs/api/resources/schemas#add-property-to-user-profile-schema and here: https://developer.okta.com/docs/api/resources/schemas#user-profile-custom-subschema

I wrote a quick and dirty example of creating a new profile schema attribute here: https://github.com/dogeared/okta-custom-profile-attribute-example

The crux of it is this code:

        ExtensibleResource result = client.http()
            .setBody(resource)
            .post("/api/v1/meta/schemas/user/default", ExtensibleResource.class);
1 Like

Thanks @micah.silverman for the example.

I presume for PUT / DELETE, the format may be similar to POST. Is it correct assumption?

One other question - When using the ExtensibleResource for GET, how do we define it such that we can pass either queryparameters or RequestBody and then retrieve the the returned JSON.

Is there any java example of how to define these?

Thanks,
Aru

Hi @mraible @micah.silverman, hope you can help me with a GET call.

I need help with the second parameter for the “get” call below. And also, how do we retrieve the returned Response from that call?

I am trying it this way

    Map<String, String> qParams = new HashMap<>();
    qParams.put("search","profile.customArrayAttr eq \"A1\"");
    MapQueryUrlencode.urlEncodeUTF8(qParams);
    client.http().setQueryParameters(qParams);
    client.http().get("https://dev-111111.oktapreview.com/api/v1/users", 
                              **"What goes here?"**);

I was trying to use ExtensibleResource for the GET call, but wasn’t able to make it work.

Note: I was able to get this work by using below construct

        ExtensibleResource response = client.http().get(
                   "https://dev-111111.oktapreview.com/api/v1/users", 
                    ExtensibleResource.class);

How do I convert ExtensibleResource to User list that the service actually returns?

Thanks,
Aru