Skip to main content
Question

How to get latest 20 User Events with Box API?

  • May 22, 2025
  • 6 replies
  • 21 views

Forum|alt.badge.img

I 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!

 

6 replies

Forum|alt.badge.img

Hey , 

 

Thanks so much for using our platform and development forum! 

 

Have you tried setting the limit query parameter? Unfortunately, dates can only be specified with enterprise events, but not user events. 

 

Best, 

Kourtney


Forum|alt.badge.img

Hey 

Thanks for your support.

I have tried limit query parameter, but result is 20 first events.

My expect is 20 latest Events.

 


Forum|alt.badge.img

Any Body can help Me? :(((((


Forum|alt.badge.img

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


Forum|alt.badge.img

Hi 

Thanks for your support.

Your solution is very good. I will implement that.

I think the better is Box provide the function to get from now to forward, not from start point to now.

 

Many thanks!


Forum|alt.badge.img

Hello,

glad this proposal works for you 🙂

 

Happy to help.

 

Best regards