box / box-python-sdk

Box SDK for Python
http://opensource.box.com/box-python-sdk/
Apache License 2.0
417 stars 214 forks source link

Collaboration.item is None #809

Closed erik-kkr closed 1 year ago

erik-kkr commented 1 year ago

Description of the Issue

I have a pending invite on a folder from another user. I can see in the UI, but I have not accepted it yet.

I like to see which folder the Collaboration object is for, yet when I retrieve it through the Python sdk however, Collaboration.item is None:

In [2]: from boxsdk import Client
   ...: from boxsdk.auth.ccg_auth import CCGAuth
   ...: 
   ...: auth = CCGAuth(
   ...:     client_id='...',
   ...:     client_secret='...',
   ...:     user='..',
   ...: )
   ...: client = Client(auth)

In [3]: for c in client.get_pending_collaborations():
   ...:     print(c, c.item)
   ...: 
<Box Collaboration - 43081159675> None

Am I holding it wrong, or is item expected to contain the Folder object? If not, how would I go about finding which item the Collaboration event is for?

Alternatively I also looked at maybe have user B provide a ShareLink, but the Python sdk does not appear to contain a parse_shared_link function?

Steps to Reproduce

Turn off auto-accept for invitation on account A. Have account B invite A on a folder. Authenticate as account A with the python boxsdk. Call the above code.

Versions Used

Python SDK: boxsdk==3.7.0 Python: 3.8

congminh1254 commented 1 year ago

Hi @erik-kkr,

You can take a look at our API specification, so the item field will be null if the invitation is pending. Our SDK only wraps endpoints from API so we are not able to change it. https://developer.box.com/reference/resources/collaboration/#param-item

You can also submit a support ticket to our CS, to request for this change.

Beside that, we also support functions get_shared_link for file, folder and weblink if you are interested.

Best regards, Minh

erikvanzijst commented 1 year ago

Hi @congminh1254, thanks for the quick reply.

If the item is None until it's accepted, is there any way to know beforehand what you are accepting?

I noticed the notifications menu on the account page in UI is able to tell what folder the invitation is for. Is this because the UI is bypassing the public API and has access to more information, or is there a different way in which I could figure out what the user is being invited to collaborate on?

congminh1254 commented 1 year ago

Hi @erikvanzijst,

I think that you can not do it with SDKs, we have a list of APIs here, if there is any endpoint can do that, we will have it in the SDK.

Best, Minh

erikvanzijst commented 1 year ago

According to the API reference, there is a client.get_shared_item() method that should return the item behind a Share Link: https://developer.box.com/reference/get-shared-items/

However, when I try to use that on my link, it fails with a 404:

In [6]: link = 'https://kkr.box.com/s/kyp5k8tl15redacted'
   ...: 
   ...: client.get_shared_item(link)
"GET https://api.box.com/2.0/shared_items" 404 158
{'Date': 'Thu, 23 Mar 2023 21:19:25 GMT', 'Content-Type': 'application/json', 'Transfer-Encoding': 'chunked', 'x-envoy-upstream-service-time': '143', 'box-request-id': '07307de0', 'cache-control': 'no-cache, no-store', 'strict-transport-security': 'max-age=31536000', 'Via': '1.1 google', 'Alt-Svc': 'h3=":443"; '}
{'code': '---ound',
 'help_url': 'http://developers.box.com/docs/#errors',
 'message': 'Not Found',
 'request_id': 'v90mv4h',
 'status': 404,
 'type': 'error'}

---------------------------------------------------------------------------
BoxAPIException                           Traceback (most recent call last)

Is this due to our custom kkr.box.com domain? The request appears to be made against api.box.com.

congminh1254 commented 1 year ago

If the API return 404, it may caused if the file is not found, or the user does not have access to the file.

So can you make sure if the link is correct and there is no password needed, or the current user have access to that link?

erikvanzijst commented 1 year ago

My bad!

The Link Share dialog had "Invited people only" set and since account A had not auto-accepted the invite, it wasn't able to see it. When I switch the link to "People in your company" it does work.