I’m having trouble figuring out the correct format for a couple of queries
I am trying to query all events that are not resolved and
a. were created within the last 24 hours
b. were created between two dates.
I’m going to be using Python with simple GET calls which I have figured out, but I just need some assistance with the advanced query for a and b above.
If anyone could lend an assist, I’d appreciate it.
Welcome to the Losant Forums, we’re happy you’re here!
a. were created within the last 24 hours
You can use the creationDate in the Advanced Event Query Schema field to query events from the last 24 hours. So you would use something like https://api.losant.com/applications/<my app id>/events?query={ "creationDate": { "$gte": X } } where X is 24 hours ago.
b. were created between two dates.
You can do this using the same query parameter as above, but providing both a start and end date. So you’d have something close to this: https://api.losant.com/applications/<my app id>/events?query={ "creationDate": { "$gte": X, "$lte": Y } }
Where X would be your starting date and Y your ending date. You can use milliseconds since epoch for both of those times.
Note: You will need to URI Encode these if you are not using any of the Losant REST Clients (the Losant REST Clients take care of this URI encoding for you).
Ah, my fault. You had mentioned you were just needed some help with A & B, but I missed that first part. I apologize!
For all events that are not resolved, you can use the state query param. But, if you are using the query query parameter , as I mentioned before, you will need to include it in the query as well because the query query parameter overrides the filterField, filter, and state parameters.
So, for events created in the last 24 hours and are unresolved, you’d use something like: https://api.losant.com/applications/<my app id>/events?query={ "creationDate": { "$gte": X }, "state": "new" }.
wouldn’t that just find events that are new. What about acknowledged? Would something like this work? Again, I guess I could test it but I want to make sure I’m doing it right.
Yes, that appears to have done what I need. We have a custom system and I don’t have access to the dashboard presented in the link. I have been using https://docs.losant.com/rest-api/schemas/#advanced-event-query which isn’t exactly intuitive. Anyway, I now have a good start so should be able to figure it out from here.