Filter users with active status and using StartsWith and Contains keywords Skip to main content
How satisfied are you with the Okta Help Center?
Thank you for your feedback!
How satisfied are you with the Okta Help Center?
Very Dissatisfied
Very satisfied
Enter content less than 200 characters.
Ask Search:
Vaibhav JoshiVaibhav Joshi 

Filter users with active status and using StartsWith and Contains keywords

Hello, does anyone have any example in .Net to search/filter user based on user's status (i.e. Active) and First/Last Name starting with a string?

We have used below sample Okta SDK code and it throws an error.
var apiToken = ConfigurationManager.AppSettings["okta:ApiToken"];
var baseUri = new Uri(ConfigurationManager.AppSettings["okta:ApiUrl"]);
var usersClient = new UsersClient(apiToken, baseUri);

var filter = new FilterBuilder()
.And(new FilterBuilder().Where(Core.Filters.User.LastName).StartsWith("J"));

foreach (Core.Models.User user in usersClient.GetFilteredEnumerator(filter))
var test = user.Profile.LastName;
var test2 = user.Profile.MobilePhone;
// Do something with each user

//Filter value as seen in debug mode is {status eq "ACTIVE" and (profile.lastName sw "J")}

ErrorCode: E0000031
ErrorID: oaeW2PeSC6_Tqy8exTTQSg7gg
ErrorSummary: Invalid search criteria.
ExceptionMessage: Exception of type 'Okta.Core.OktaException' was thrown.
Stack Trace:
   at Okta.Core.OktaExceptionResolver.ParseHttpResponse(HttpResponseMessage httpResponseMessage)
   at Okta.Core.OktaHttpClient.Execute(HttpRequestType requestType, Uri uri, String relativeUri, String content, Int32 waitMillis, Int32 retryCount, Boolean bAddAuthorizationHeader)
   at Okta.Core.Clients.ApiClient`1.GetList(Uri nextPage, Int32 pageSize, FilterBuilder filter, SearchType searchType, String query, String after, Nullable`1 startDate)
   at Okta.Core.Clients.ApiClient`1.GetFilteredEnumerator(FilterBuilder filter, SearchType searchType, Int32 pageSize, String query, String after, Nullable`1 startDate)
   at Okta.Web.MvcApplication.Application_AuthenticateRequest(Object sender, EventArgs e) in C:\PoC\Okta\Okta.Web\Global.asax.cs:line 60
   at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

Please suggest. Thanks in advance.
Jaypee ManansalaJaypee Manansala (Okta)
Hi Vaibhav,

Thanks for posting your inquiry in Okta Community.

I have attached a link to give you guidance on to "list users" using Search. I do recommend to use "Search" expression instead of "Filter". Please check the article "List Users with Search"

Please let me know if you need any additional information or call Okta Support for further assistance. Thank you.