Skip to main content

Hello,



I am working on a Python integration that requests Box API.



My goal is as follows: to set up an automation that invites one or more individuals to collaborate on a file/folder. Once the invitation is accepted, an approval task is created on the file (or on each file within a folder) and assigned to the same person.



However, how can I invite a user who does not have a Box account? The request to create a collaboration requires an object of type ‘User (Collaborations)’. Yet, I only have the email address and not a user ID.



Thank you in advance for helping me through my issue.



Antoine

Hi there @Ooshot , welcome to the community!



Box does have the concept of external users.



But I’m wondering what feature would be best applicable here, maybe shared links?



Can you elaborate your use case a bit more?



For example I invited an external user for collaboration on a folder (notice the external user icon):





In the admin console, this user shows up on the External users tab:





However if the external user does not have a Box account yet, it will be invited to create a new free account.



This is what the external user view looks like for the collaborated folder:





Would this create a free box account for the external users be a problem for your use case?



Also please elaborate what you want to accomplish for the approval task flow.



Cheers


Hi there,



Thank you very much for your help!



I considered using a Shared Link to accomplish my goals, but it’s not suitable because an external user cannot leave comments or be assigned a task. Let me explain in more detail what I want to do. Perhaps you’ll have other suggestions.



I want to deliver photo and/or video content to multiple clients. My teams upload the files to a directory on Box, and then, using the API and a webhook configured on the directory, the client receives an email to access the files. The client can then view and even download the files. I want them to be able to provide feedback on the file quality directly on Box, using comments (the right sidebar). For example, let’s say they want the text appearing on an image to be larger or a different color, etc., they should indicate that in the comments.



Next, I would like them to be able to approve or disapprove the content by clicking a button. This allows me to send a webhook request to my server for further processing. For example, if the client approves the file, we can initiate the billing process. If they disapprove, an automated email can be sent to the relevant people. For this, I found that “approval tasks” seem suitable: I would just need to create an approval task for each file, assigned to the client, with a title like “Approve the content?”.



I hope you understand better my need and I am looking forward to hearing from you.



Cheers,


Antoine


Great, thanks for the insight.



Seems perfectly doable.



Let’s start by how to “collaborate” external users, here is a sample script for you:



from boxsdk import OAuth2, Client

from boxsdk.object.collaboration import CollaborationRole





DEV_TOKEN = "ILH...KW"

FOLDER_ID = "213534631621"

# AS_USER_ID = "213534631621"





def main():

auth = OAuth2(

client_id="",

client_secret="",

access_token=DEV_TOKEN,

)

client = Client(auth)



# who am I?

me = client.user().get()

print(f"I am {me.name} ({me.login})")



# get the folder

folder = client.folder(folder_id=FOLDER_ID).get()

print(f"Folder name: {folder.name} ({folder.id})")



# collaborate folder to external user

collab = folder.collaborate_with_login(

"barbasr+222@gmail.com", CollaborationRole.EDITOR

)

print(

f"Collaboration ID: {collab.id} status: {collab.status} role: {collab.role} invite: {collab.invite_email}"

)



# get the folder collaborators

collaborators = folder.get_collaborations()

print(f"Folder {folder.name} ({folder.id}) collaborators:")

for collaborator in collaborators:

print(

f"\tCollaborator: {collaborator.id} {collaborator.status} role: {collaborator.role} invite: {collaborator.invite_email})"

)



# remove the collaboration

collab.delete()





if __name__ == "__main__":

# Execute main()

main()





The output looks like this (on my machine 🙂):



I am Rui Barbosa (barduinor@gmail.com)



Folder name: 4PL8AF (213534631621)



Collaboration ID: 45548719393 status: pending role: editor invite: barbasr+222@gmail.com



Folder 4PL8AF (213534631621) collaborators:

Collaborator: 45548719393 pending role: editor invite: barbasr+222@gmail.com)

Collaborator: 45550301448 accepted role: editor invite: None)



Collaboration 45548719393 deleted



In essence the collaborations end point accepts an internal user, an external user or a group id, so you can do for an internal user:



user = client.user(user_id='11111')

collaboration = client.folder(folder_id='22222').collaborate(user, CollaborationRole.VIEWER)



or for a group:



group = client.group(group_id='11111')

collaboration = client.folder(folder_id='22222').collaborate(group, CollaborationRole.VIEWER)



or for any user (including external users)



email_of_invitee = 'testuser@example.com'

collaboration = client.folder(folder_id='22222').collaborate_with_login(email_of_invitee, CollaborationRole.VIEWER)



Let us know if this helps



Cheers


2 posts were split to a new topic: Is collab.id the same as user.id?


Reply