Copy and Delete
Learn how to perform copy and delete operations using the Dropbox API.
We'll cover the following...
In this lesson, our goal is to explore the endpoints of the file namespace that allow us to copy content from the source to the destination path and delete content. The endpoint operations we’ll focus on are the following:
copy_v2delete_v2
Copy a file or a folder
The /files/copy_v2 endpoint lets us copy a file or folder to another location in Dropbox. If the specified source path is a folder, then all of its content will be copied. This endpoint requires us to enable the files.content.write permission.
Request parameters
Let’s see some of the parameters for this call in the table below.
Note: We’ve manually added some files to the
TestFolderthat we created in the previous lesson so that we may copy them to another folder.
Parameter Name | Description | Format | Required |
| This is the path to the Dropbox folder or file that we want to copy. | String | Yes |
| This is the destination path to the user's Dropbox. | String | Yes |
| This is set to | Boolean | No |
In the code above, we see the following:
- Lines 11–15: We show our
datato be sent to the endpoint. - Lines 12 and 13: We show both the
sourcepath and thedestinationpath, respectively. In thedestinationpath, we’ll create a new folder calledDestFolder. - Line 14: We assign
Truetoautorename. If the/homedirectory already has a folder namedDestFolder, then Dropbox will automatically rename our requested folder. - Line 17: This is the HTTP request.
- Line 18: We print the response.
Response fields
In response to the execution of the code above, we’ll get the .tag, name, path_lower, path_display, and id of our folder or file. Now, in our Dropbox account, we’ll see a new folder was created at the specified path and the content was copied into it.
Delete a file or a folder
The files/delete_v2 endpoint deletes a file or a folder from a specified location. If we provide a path to a folder, then all of its content will also be deleted. It requires us to enable the permission files.content.write to perform this action.
Let’s delete the DestFolder that we created with the copy_v2 endpoint.
Request parameters
Let’s see the request parameters, descriptions, and formats in the table below.
Parameter Name | Description | Format | Required |
| This is the path of the file or folder to be deleted. | String | Yes |
| This is only applicable to files. A file will only be deleted if the current revisions match the file's most recent revisions. | String | No |
In the code above, we see the following:
- Lines 11–13: We present our data with the
pathparameter, which contains the value/home/DestFolder. - Line 15: We define the
POSTrequest. - Line 16: We print the response.
Response fields
Our call’s response will provide the metadata of the deleted folder, which includes the name, path_display, id, and so on.