Remove a Folder Member and Unshare it
Learn how to remove a folder member and unshare a folder using the Dropbox API.
We'll cover the following...
In this lesson, we’ll explore some more endpoints of the sharing namespace, which include the following:
remove_folder_memberunshare_folder
Remove a folder member
The sharing/remove_folder_member endpoint is used to remove a specific member from a folder. Only the members with owner or editor rights can perform this task. This endpoint also needs us to enable the sharing.write permission.
Request parameters
It takes three required parameters, which are outlined in the following table:
Parameter Name | Format/Value | Required | Description |
| String | Yes | Unique ID of the shared folder. |
|
| Yes | Defines which member should be removed. They can be specified with their |
| Boolean | Yes | Indicates whether the removed member will keep a copy of the unshared folder or not. |
The code below will remove the folder member with the email user_id@gmail.com we added in the previous lesson.
In the code above, we see the following:
- Line 2: We import the
fetchlibrary that we need to use in our code fromnode-fetch. - Line 5: We get the value for
TOKENto use for authentication. - Line 8: We define the request URL.
- Lines 11–14: We define the
headersof thefetchrequest. It includes the authorization and the type of content, which isapplication/jsonin most cases. - Lines 17–23: We define the
bodyParametersof thefetchrequest. - Lines 26–30: We set the API call options.
- Lines 33–43: We create a function to make the API call. It will
tryto get the response and will pass the response to the custom functionprintResponse; otherwise, it willcatchthe error and will pass it to the custom functionprintError. - Line 46: We call the function
removeMemberto make the API call.
Response
This operation works in exactly the same way as share_folder in that it can be executed synchronously or asynchronously. With synchronous execution, our response is just a completion message. However, if it’s executed asynchronously, async_job_id will be returned in the response, and we’ll have to check the status of the operation like we did with share_folder and use the same endpoint.
If async_job_id is returned by the code, then we’ll use the check_job_status endpoint. We’ll replace the placeholder {async_job_id} in line 18 with the async_job_id returned by the previous block of code. It’ll produce a complete response once the operation is done.
Unshare the folder
The /sharing/unshare_folder endpoint permits the folder members with owner rights to unshare the folder. This endpoint also requires us to have the permission sharing.write enabled.
Request parameters
This endpoint has one required and one optional parameter. Let’s take a look at them in the following table:
Parameter Name | Format | Required | Description |
| String | Yes | Unique ID of the shared folder that we obtained in the previous lesson. |
| Boolean | No | If it’s set to |
The following code unshares a shared folder:
In the code above, we do the following:
- Line 2: We import the
fetchlibrary that we need to use in our code fromnode-fetch. - Line 5: We get the value for
TOKENto use for authentication. - Line 8: We define the request URL.
- Lines 11–14: We define the
headersof thefetchrequest. It includes the authorization and the type of content, which isapplication/jsonin most cases. - Lines 17–19: We define the
bodyParametersof thefetchrequest. - Lines 22-26: We set the API call options.
- Lines 29–39: We create a function to make the API call. It will
tryto get the response and will pass the response to the custom functionprintResponse; otherwise, it willcatchthe error and will pass it to the custom functionprintError. - Line 42: We call the function
unshareFolderto make the API call.
Response
This operation can work synchronously or asynchronously. If it’s synchronously executed, the response is just a completion message. If the execution is asynchronous, the response will be async_job_id, and we’ll have to check the status of the operation by executing the check_job_status endpoint from the previous section.
Note: After getting the
completestatus of the above asynchronous job, visit thepreview_urlagain in the browser. You’ll notice that the folder’s shareable link is no longer valid.