How to get latest 20 User Events with Box API?
AnsweredI want to get latest 20 User Events with Box API.
I tried:
get all events with LOOP
https://api.box.com/2.0/events?limit=500&stream_position=0&stream_type=all
stream_position = next_stream_position
AND get latest 20 events. But it take very long time.
So have an other way to get latest 20 User Events?
Can I set stream_position to special past date?
Any body help me? Please!
-
Hello ,
I've not used this endpoint but as per documentation there are important points:
- Because of its emphasis on returning complete results quickly, Box may return duplicate events, and events may delivered out of order.
- "next_stream_position": 1348790499819,
I understand from these two points that you may never be sure that the last 20 are actually the last ones. But most important, BOX shows the next stream position but not the previous one. So, you can not start from "now" and go backwards.
So I think that the approach you are using is the only option. Not the best one as it will take a lot of API calls and a lot of time to reach the last elements.
The Only option I can think of is to use the "now" value for stream_position. So, you can query the full list now till you have the 20 last. Then, you should cache the last stream position somewhere or the "now" one, and every time you run your query use that value and update it with the latest. So you can start gathering always from that point and not from the beginning.
Thanks
Please sign in to leave a comment.
Comments
6 comments