Level up your Box knowledge with brand new learning paths on Box University. Visit training.box.com to get started

API Access Stats (Python SDK)

Answered
New post

Comments

4 comments

  • jheck

    As a solution, I am trying to filter the events using the event_type

    events = client.events().get_events(limit=10000, stream_position=0)
        for e in events['entries']:
            if (e['event_type'] in ('ITEM_PREVIEW')):

    But I am not sure this is the most optimal way since I am targetting a subfolder only. Plus it looks like we are limited by the events limit.

     

    Are there any function like:

    client.file(file_id=k.object_id).access_stats

     

    Any suggestion are really welcome!

     

    Thanks.

    0
    Comment actions Permalink
  • Bibek

    Hi there,

     

    I think you are in right track. I do events like this:

     

    stream_pos = 0
    count = 0
    while True:
        events = dclient.events().get_events(limit=100,stream_position =stream_pos)
        for e in events['entries']:
            if e['event_type'] == 'ITEM_PREVIEW':
            print(e['created_by']['login'] +" created at: "+e['created_at'] +" Name: "+e['source']['name'])
        stream_pos = events['next_stream_position']

        if count == 100:
            break;
        count += 1

     

    Sample output:

    ***email address removed for privacy*** created at: 2017-06-09T15:44:01-07:00 Name: valarian_sword.docx

     

    so,basically this codes goes through the events API and gets the next stream position. In this case limit doesn't really matter but the variable "count" matters. The more you make the count go , the more events you get.  Once you get the required events, it's all up to you to parse/ count whatever you want to do.

     

    I hope this helps.

     

    thanks,  

    Bibek

    0
    Comment actions Permalink
  • jheck

    Thanks Bibek!

     

    I just came with a very similar solution. But still one issue remains: are you able to get stream events older than 1 month ago?

     

    stream_position=0
    
    events = client.events().get_events(limit=100, stream_position=stream_position)

     

    The above code doesn't return stream events older than 1 month from today's date, even if the documentation it says that "0 is the beginning of time". 

     

    Thanks!

     

    0
    Comment actions Permalink
  • Bibek

    Well, i haven't tried to get older events but Box API doc says this:

     

    User Events Retention Policy - We store user events for between 2 weeks and 2 months, after which they are removed.

    Enterprise Events Retention Policy - Enterprise events are accessible for up to 7 years via the reports section in the Box Admin Console. Enterprise events are accessible for up to 1 year via the Enterprise Events endpoint.

    https://developer.box.com/v2.0/reference#events

     

    It does say 2weeks to 2 months for User events so,it might be that some type of events are not stored for more than a month.You need find that out  -may be to create box support and ask them about it if you don't get answers here. 

     

    thanks, 

    Bibek

     

    0
    Comment actions Permalink

Please sign in to leave a comment.