0

Is there a way to get the latest event of a specific type from a specific device? So far I queried all events via myURL/event/events?source=<<ID>>&type=<<type>>.

Or is there a way to get a collection of events ordered by their creationTime? This could solve my problem too

In the documentation I only found parameters like dateFrom and dateTo. But what if I don't know the time range of the last event?

d4rty
  • 3,970
  • 5
  • 34
  • 73

3 Answers3

0

The syntax is: /event/events?type={type}&source={source}.

For more information on the available endpoints: GET /platform

Georgi
  • 165
  • 1
  • 9
  • But this will give me all the events. I'm looking for a way to get only the latest event. – d4rty Apr 25 '16 at 08:13
  • I thought about to limit the number of events by adding `pageSize=1`, but this won't work because you won't get the latest event (ordered by the creationTime variable). – d4rty Apr 25 '16 at 08:23
  • Then you can use: /event/events?source={source}&dateFrom={dateFrom}&dateTo={dateTo}&type={type}", however I guess you are not guaranteed to get any events... – Georgi Apr 25 '16 at 13:50
  • And if i don't know the date range from the last event? – d4rty Apr 25 '16 at 13:54
  • The other APIs support a parameter revert=true to change the sorting order and get the last measurement. However, it hasn't been added to events. Feel free to ask for such a capability on the support line. – André Apr 25 '16 at 13:54
0

Answer from the support-team:

currently there is no way to revert the order of events. Besides dateFrom and dateTo you can also use creationFrom and creationTo. This will take the creationTime (server side timestamp when event was created) instead of the time (that is send within the event) But the order will still be oldest -> newest.

Best approach currently would be to use a good estimated time range (so you don't end up with 0 events in the response) where the dateTo/creationTo is in the future. If you add to the query params withTotalPages=true the result will give you the total pages in the statistics part.

Knowing the total pages you can you can do the query again but with currentPage=XX instead of withTotalPages=true and take the last element.

We have this functionality on measurements and audits where you can add the parameter revert=true. I will add an improvement that we extend this to the other APIs but at the moment you are limited to the workaround.

d4rty
  • 3,970
  • 5
  • 34
  • 73
0

You can just only set the dateFrom parameter and the pageSize to 1 like so: &pageSize=1&dateFrom=1970-01-01. As of September 2017, this returns the most recent event.

turbopope
  • 33
  • 4