Filtering Events API | Python
回答済みTeam -- Need help with adding filters to an API call I am making.
I am able to get a response from the API. Mostly followed this page or something similar
But, when I try to add filters shown here, they error out (mind you I am using get_events versus what is shown, but documentation says the filters should be available as long as using admin_logs.
This pull works fine after authenticated and pulls back the info I need... but would like to filter it
events = client.events().get_events(stream_type="admin_logs", limit=500)
stream_position = events['next_stream_position']
for event in events['entries']:
print(event.response_object)
When I make some changes to add in a filter like shown in the docuemntation
stream_position = 0
events = client.events().get_events(stream_type="admin_logs", limit=500, event_types=['ITEM_CREATE'])
stream_position = events['next_stream_position']
for event in events['entries']:
print(event.response_object)
I get
TypeError: get_events() got an unexpected keyword argument 'event_types'
When I run the exact example in the link it also errors:
events = client.events().get_admin_events_streaming(event_types=['ITEM_CREATE'])
for event in events['entries']:
print('Got {0} event that occurred at {1}'.format(event.event_type, event.created_at))
AttributeError: 'Events' object has no attribute 'get_admin_events_streaming'
What are the arguments for events()?
-
Hi Kishan Patel
Filtering events by `event_types` is only available for admin logs.
So to do that you need to use one of these two methods:events = client.events().get_admin_events(event_types=['ITEM_CREATE'])
or
events = client.events().get_admin_events_streaming(event_types=['ITEM_CREATE'])
Please take a look into events documentation on python SDK for more details here
The documentation that you pointed is related to the newest version of our SDK which is v.2.14.0.
And in that version get_admin_events_streaming method was added.So I suppose you are using the older version and that's why you have this following issue:
AttributeError: 'Events' object has no attribute 'get_admin_events_streaming'
If you want to use this method, please update version of our SDK with the following command:pip install boxsdk --upgrade
Hope this helps!
サインインしてコメントを残してください。
コメント
1件のコメント