Java SDK - fitlering users

Hi,

I am trying to use the Java SDK to list users using a filter. I can get a Curl request to work properly but have not hit on the correct encoding of the method parameters to get the filter to work. I’d like to filter by profile.emailVerificationStatus.

/api/v1/users?filter%3Dprofile.emailVerificationStatus%20eq%20%22UNVERIFIED%22&limit=200

This works properly with Curl, but when used in the listUsers() method as the second parameter, the response is always “Invalid search criteria.”

UserList users = client.listUsers(null, "profile.emailVerificationStatus eq \"UNVERIFIED\"", null, null, null);

I haven’t tested the code but give this a try -
UserList users = client.listUsers(null, 'profile.emailVerificationStatus eq \"UNVERIFIED\"', null, null, null)

Also, you can take a look at our integration tests for API usage - https://github.com/okta/okta-sdk-java/blob/master/integration-tests/src/test/groovy/com/okta/sdk/tests/it/UsersIT.groovy

@bdemers - This should work right?

@chrisc can you paste the code within a code block (to make sure the quotes are correct):
```
code here
```

@vijet should be right, but adjusting for Java instead of groovy:
"profile.emailVerificationStatus eq \"UNVERIFIED\""

Here is the exact line that fails.

UserList users = client.listUsers(null, "profile.emailVerificationStatus eq \"UNVERIFIED\"", null, null, null);

From the logs I can see this is then translated to the following GET:
“GET /api/v1/users?filter=profile.emailVerificationStatus+eq+%22UNVERIFIED%22 HTTP/1.1[\r][\n]”

With error response:
{“errorCode”:“E0000031”,“errorSummary”:“Invalid search criteria.”,“errorLink”:“E0000031”,“errorId”:“oaeC6n-sySnQCmL-0eDG4qumw”,“errorCauses”:[]}[\r][\n]

Hey @chrisc

The issue is with the filter itself. I didn’t notice it the first time, but your original curl href was:

/api/v1/users?filter%3Dprofile...

It looks like your = char is escaped. Resulting in the query parameter key being that whole string.

Take a look at the doc for the user filter:

Supports only a limited number of properties: status, lastUpdated, id, profile.login, profile.email, profile.firstName, and profile.lastName.

This will be supported via the search param in the future:

It is strange then since this filter query can be run against the API using Curl:

curl -H ‘Accept: application/json’ -H ‘Content-Type: application/json’ -H ‘Authorization: SSWS xxx’ ‘https://xxxx.oktapreview.com/api/v1/users?filter%3Dprofile.emailVerificationStatus%20eq%20"UNVERIFIED"&limit=200

@chrisc
It is similar to running /api/v1/users?invalid you need to replace the %3D with and = and you should see the same error. (you have the equals char escaped)

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.