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

**URL:** <https://devforum.okta.com/t/is-there-a-way-to-change-the-attributes-for-a-user-programmatically-using-the-okta-sdk/4048>\
**Category:** Questions\
**Tags:** java\
**Created:** [January 26, 2019, 9:02pm UTC](https://devforum.okta.com/t/is-there-a-way-to-change-the-attributes-for-a-user-programmatically-using-the-okta-sdk/4048 "2019-01-26T21:02:34Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![adbdkb](https://avatars.discourse-cdn.com/v4/letter/a/77aa72/32.png) [@adbdkb](https://devforum.okta.com/u/adbdkb)\
**Post date:** [January 26, 2019, 9:02pm UTC](https://devforum.okta.com/t/is-there-a-way-to-change-the-attributes-for-a-user-programmatically-using-the-okta-sdk/4048/1 "2019-01-26T21:02:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mraible](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/mraible/32/37_2.png) [@mraible](https://devforum.okta.com/u/mraible)\
**Post date:** [January 26, 2019, 10:59pm UTC](https://devforum.okta.com/t/is-there-a-way-to-change-the-attributes-for-a-user-programmatically-using-the-okta-sdk/4048/2 "2019-01-26T22:59:10Z")

</div>

[This blog post](https://developer.okta.com/blog/2018/01/23/replace-local-storage-with-okta-profile-attributes) shows you how to use the Java SDK to get/set a custom attribute. Hope it helps!

---

<div class="post-metadata">

**Author:** ![adbdkb](https://avatars.discourse-cdn.com/v4/letter/a/77aa72/32.png) [@adbdkb](https://devforum.okta.com/u/adbdkb)\
**Post date:** [January 27, 2019, 3:51am UTC](https://devforum.okta.com/t/is-there-a-way-to-change-the-attributes-for-a-user-programmatically-using-the-okta-sdk/4048/3 "2019-01-27T03:51:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mraible](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/mraible/32/37_2.png) [@mraible](https://devforum.okta.com/u/mraible)\
**Post date:** [January 27, 2019, 4:12am UTC](https://devforum.okta.com/t/is-there-a-way-to-change-the-attributes-for-a-user-programmatically-using-the-okta-sdk/4048/4 "2019-01-27T04:12:31Z")

</div>

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://twitter.com/mraible)

[https://developer.okta.com/blog](https://developer.okta.com/blog)

---

<div class="post-metadata">

**Author:** ![adbdkb](https://avatars.discourse-cdn.com/v4/letter/a/77aa72/32.png) [@adbdkb](https://devforum.okta.com/u/adbdkb)\
**Post date:** [January 27, 2019, 12:56pm UTC](https://devforum.okta.com/t/is-there-a-way-to-change-the-attributes-for-a-user-programmatically-using-the-okta-sdk/4048/5 "2019-01-27T12:56:47Z")

</div>

Thanks Matt. Created an [issue](https://github.com/okta/okta-sdk-java/issues/258) on Project’s Gitbub

---

<div class="post-metadata">

**Author:** ![micah.silverman](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/micah.silverman/32/1239_2.png) [@micah.silverman](https://devforum.okta.com/u/micah.silverman)\
**Post date:** [January 28, 2019, 6:24am UTC](https://devforum.okta.com/t/is-there-a-way-to-change-the-attributes-for-a-user-programmatically-using-the-okta-sdk/4048/6 "2019-01-28T06:24:20Z")

</div>

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](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](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](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](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);
```

---

<div class="post-metadata">

**Author:** ![adbdkb](https://avatars.discourse-cdn.com/v4/letter/a/77aa72/32.png) [@adbdkb](https://devforum.okta.com/u/adbdkb)\
**Post date:** [January 28, 2019, 10:04pm UTC](https://devforum.okta.com/t/is-there-a-way-to-change-the-attributes-for-a-user-programmatically-using-the-okta-sdk/4048/7 "2019-01-28T22:04:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![adbdkb](https://avatars.discourse-cdn.com/v4/letter/a/77aa72/32.png) [@adbdkb](https://devforum.okta.com/u/adbdkb)\
**Post date:** [January 30, 2019, 12:14am UTC](https://devforum.okta.com/t/is-there-a-way-to-change-the-attributes-for-a-user-programmatically-using-the-okta-sdk/4048/8 "2019-01-30T00:14:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![andrea](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/andrea/32/2172_2.png) [@andrea](https://devforum.okta.com/u/andrea)\
**Post date:** [January 17, 2024, 7:35pm UTC](https://devforum.okta.com/t/is-there-a-way-to-change-the-attributes-for-a-user-programmatically-using-the-okta-sdk/4048/9 "2024-01-17T19:35:34Z")

</div>

Closed on January 17, 2024, 7:35pm UTC


