Add, List, and Remove a File Member
Learn how to add a new file member, get a list of all members with access to a file, and remove a specific file member using the Dropbox API.
In this lesson, we’ll learn about the sharing namespace offered by the Dropbox API. The endpoints of this namespace are used to create and manage shared links and folders. We’ll explore the following operations in this lesson:
add_file_memberlist_file_membersremove_file_member_2
Note: The endpoints of the sharing namespace only support applications with full Dropbox access. For example, if you’ve created an application that has “App folder” access, then this endpoint won’t work.
Add a member to a file
The /sharing/add_file_member endpoint adds a user to a file. This endpoint requires us to enable the sharing.write permission to perform this task.
Request parameters
Let’s see which parameters we can pass to this endpoint call.
Parameter Name | Description | Format | Required |
| This defines the file to which we want to add a member. We can use the name of the file with the complete path or ID of a file. | String | Yes |
| This is a list of users that we want to add to the file we indicated in the previous parameter. Members can be specified by their Dropbox ID or email address. | String | Yes |
| We can include a message to be sent to the newly added member. | String | No |
| This parameter tells us how the member should be notified—for example, by email or device notifications. By default, it’s set to | Boolean | No |
| This defines the role of our newly added member. It could be | Object | No |
| If this parameter is set to | Boolean | No |
In the code below, we’ll add a member to a file.
In the code above, we see the following:
- Lines 11–18: We define our
dataobject. - Line 12: This shows our file’s path with the file name at the end of the string.
- Line 13: This shows the list of members to add, which includes their
tagandemailaddress. Thetagdefines whether a member will be added with their Dropbox ID or their email ID. - Lines 14–17: We present the remaining parameters as we’ve defined them in the table above.
- Line 20: We define the
POSTrequest. - Line 21: We print the response.
Note: We can only specify the
access_levelsparameter aseditororviewer.
Response
The code will return a list that includes metadata of the added member (such as their role) and the outcome or status of this call.
List file members
This endpoint will give us a list of all the members that have access to the shared file. The /sharing/list_file_members endpoint requires us to enable the sharing.read permission to perform this task.
Request parameters
Let’s see some of the parameters in the table below that we’ll need to use in our practice code.
Parameter Name | Description | Format | Required |
| This is the ID of the file for which we want to get a list of members. | String | Yes |
| This tells us if we want to include members who have obtained access to a file from a shared parent folder. By default its value is set to | Boolean | No |
| This is the maximum number of members to return per query. By default its value is | UInt32 | No |
In the code below, we’ll use the search_v2 endpoint to get the file ID for demo.png.
The code above will give all files with the name demo. Copy the ID of demo.png and paste it into line 12 of the code below.
In the code above, we see the following:
- Lines 11–14: We define the
dataobject, which includes thefileandinclude_inheritedparameters. The file ID is for thedemo.pngfile, which is underTestFolder. - Line 16: This is the HTTP request.
- Line 17: This is the print statement.
Response
Successful execution of the list_file_members endpoint returns three separate lists of users, groups, and invitees. It also returns a cursor. Let’s describe these response fields in some more detail.
- The field
usersindicates a list of members who have access to the shared file.- The
access_typedefines the role of the member—for example, if the member is theowner,viewer,editor, orviewer_no_comment. - A
userdefines the account information of the file member (user)—for example, theirname,id,email, and so on. - The value
is_inheritedtells us if the file member was given or obtained access from the parent folder. If this is the case, then its value isTrue.
- The
- The field
inviteesis a list composed of members who were invited to this file but haven’t registered and/or accessed this invitation. It includes almost all the same fields included in theuserslist. - The
cursoris used to fetch other members if there are other members who have not been returned in our results.
Remove a file member
Let’s remove a specific member from a file using the /sharing/remove_file_member_2 endpoint of the sharing namespace.
Request parameters
This request takes two required parameters. The first is the file parameter, which is assigned the file ID, and the second is the member parameter, which states the tag and email of the member to be removed.
Now, let’s remove the member that we added to the demo.png file using the add_file_member endpoint.
Parameter Name | Description | Format | Required |
| This is the file ID or path, including the file's name, from which we want to remove a member. | String | Yes |
| We can indicate here how we want to remove a file member. It’s specified by the value of | Open Union | Yes |
In the code below, we’ll remove a specific member from a file.
In the code above, we see the following:
- Line 12: This shows the
fileparameter, we’ve specified the path of ourdemo.pngfile. - Line 13: This shows the
memberand includes thetagthat defines if we’ll specify the file member’s Dropbox ID or email address. Next, we have given an email ID based on thetagtype. - Line 16: This is the
POSTrequest to the endpoint. - Line 17: We print the response of our call.
Response
The code only returns the tag field with the success value.