Skip to main content
Question

Python SDK question - folder.has_collaborators not found

  • May 22, 2025
  • 4 replies
  • 20 views

Forum|alt.badge.img

Hello,

I am trying to determine with the Python SDK and Box API how to see if a file or folder is being shared. I looked at the Box documentation and there looks to be an attribute of the folder object called has_collaborators, but is not a valid parameter.

 

I looked over the BOX SDK docs and its says I can query the folder object with a string of parameters, but I didnt see a place where valid parameters were.. 

Things I do see, are name, owned_by, and item size, but I really need to know if a item is being shared.

 

How do I look at the parameters or attributes of a object collection? If i can just pprint it, that would have been awesome, but that alas doesnt work.

 

Thanks for the help,

Gary

 

4 replies

Forum|alt.badge.img

 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')) 

Forum|alt.badge.img

 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

 


Forum|alt.badge.img

 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?


Forum|alt.badge.img

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!