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

Python SDK question - folder.has_collaborators not found

Answered
New post

Comments

4 comments

  • mwiller

     The has_collaborators field on File and Folder objects is not returned from the API by default; you'll need to specifically request it.  You can do this by passing a list of field names you want returned to the folder.get() method, like this:

     

    folder = client.folder('FOLDER_ID').get(fields=['has_collaborators'])
    print('The folder {} collaborators'.format('has' if folder.has_collaborators else 'does not have')) 
    0
    Comment actions Permalink
  • gwaters

     I clicked "Solution" too fast, this doesnt work. 

     

    I get this error:

    AttributeError: 'Folder' object has no attribute 'has_collaborators'

     

    if item.type == 'folder':
    item_info = self.client.as_user(user).folder(folder_id=item_id).get(fields=['has_collaborators'])
    if item.type == 'file':
    item_info = self.client.as_user(user).file(file_id=item_id).get(fields=['has_collaborators'])
    if item_info.has_collaborators:
    shared=True

     

    0
    Comment actions Permalink
  • mwiller

     Ah, I think I see one issue — the field in the API docs is called has_collaborations, not has_collaborators.  If you use that, does it work correctly?

    0
    Comment actions Permalink
  • gwaters

    From The Box API Docs: 

    has_collaborations - boolean - Whether this file has any collaborators.

     

    I must have misread that like 20 times.. Wow.. thank you.  I read "has any collaborators" and magically mentally renamed the parameter to match. Sigh. Thanks again!

     

    0
    Comment actions Permalink

Please sign in to leave a comment.