API for getting users that have been updated since a timestamp
-
Is there an API which can provide all users that have been updated since a certain timestamp? By updated I mean their name, username, email, or password has changed.
We are using the Java client (but can use HttpClient to access FusionAuth web APIs directly) and are calling
FusionAuthClient.searchUsersByQuery()
. I am unable to find an example of a query we can use inUserSearchCriteria.queryString
of theSearchRequest
- is there a way to do this? -
Hi @jason!
You have a few choices to consider.
Option A - On User
You could consider the below attributes on the user and mold your query by accessing them.
On
Users/User
, you have the ability to access-
user.insert_instant
,users[x].insert_instant
This is when the searched for user/users were created. -
user.last_update_instant
Is another option as well. However, the user tends to be updated frequently in the database without any data actually changing. It simply represents the last time the DB table was written to. See webhooks below for a better solution.
Some documentation can be found here, but admittedly, we will be updating it shortly to reflect the fields mentioned above. You may have already reviewed this, but posting for others benefit as well
Option B - Webhooks
A more compelling option might be to use webhooks to record when a user record changes and act per your business requirements to that change.
The webhooks documentation can be found here:
- https://fusionauth.io/docs/v1/tech/events-webhooks/#overview
- https://fusionauth.io/docs/v1/tech/events-webhooks/events/
I hope this helps!
Thanks,
Josh -
-
To add to what @joshua said, we don't record when "name, username, email, or password" has changed. The last update timestamp will be modified whenever anything about a user object changes. So if you are only interested in those changes, a webhook to an external system is the best solution.
If you are ok with using the last update timestamp, I don't think you can query that with the
queryString
. I think you'll need to use a fullquery
parameter. There are examples of ranges in the user search docs Joshua links to, but here's an example I copied and munged from there (so haven't tested it, but it should give you a starting point):{ "range": { "lastUpdateInstant": { "gte": 1618691124000, "lte": 1618691224000 } } }
You'll need to escape that JSON and provide it as the
query
parameter (either in the url query string or in the form post object).