Update and Delete a File Request
Learn how to update and delete a file request.
We'll cover the following
In this lesson, we’ll encounter two very important operations within the file_requests
namespace:
update
delete_all_closed
They both require us to enable the file_requests.write
permission.
Update a file request
We use the /file_requests/update
endpoint to update the properties of a file request. It uses the same parameters as the /file_requests/create
endpoint. Let’s update the title of the file request and close it.
// Define import libraries hereimport fetch from 'node-fetch';// Define API key hereconst token = '{{TOKEN}}'// Define endpoint URL hereconst endpointUrl = new URL('https://api.dropboxapi.com/2/file_requests/update');// Define Header Parameters hereconst headerParameters = {'Authorization': `Bearer ${token}`,'Content-Type': 'application/json',};// Define Body Parameters hereconst bodyParameters = JSON.stringify({id: "{{FILE_ID}}",title: "Let's modify demoFileByAPI",open: false});// Set the API call optionsconst options = {method: 'POST',headers: headerParameters,body: bodyParameters,};// Function to make the API callasync function callUpdateRequest() {try {const response = await fetch(endpointUrl, options);// Custom function for printing the API responseprintResponse(response);} catch (error) {// Custom function for printing the error messageprintError(error);}}// Call function to make the API callcallUpdateRequest();
In the code above, we do the following:
- Line 2: We import the
fetch
library that we need to use in our code fromnode-fetch
. - Line 5: We get the value for
TOKEN
to use for authentication - Line 8: We define the request URL.
- Lines 11–14: We define the
headers
of thefetch
request. It includes the authorization and the type of content, which isapplication/json
in most cases. - Lines 17–21: We define the
bodyParameters
of thefetch
request. These include theid
andtitle
of the request. Theopen
parameter defines whether or not the file request should be open. If the file request isclosed
, it will not accept any file submissions. - Lines 24–28: We set the API call options.
- Lines 31–41: We create a function to make the API call. It will
try
to get the response and will pass the response to the custom functionprintResponse
; otherwise, it willcatch
the error and will pass it to the custom functionprintError
. - Line 44: We call the function
callUpdateRequest
to make the API call.
Response fields
After we’ve successfully executed the code above, the properties of the file request will be returned with updated values. Now, we’ll visit the Dropbox dashboard and select the “File requests” option, followed by the “Closed” tab. We’ll see our closed file request here.
The properties that weren’t mentioned in our call will remain unchanged—for example, the destination
and description
properties.
Delete all closed file requests
The /file_requests/delete_all_closed
endpoint allows us to delete all file requests that have been closed. It requires us to enable the file_requests.write
permission and doesn’t take any parameters.
// Define import libraries hereimport fetch from 'node-fetch';// Define API key hereconst token = '{{TOKEN}}'// Define endpoint URL hereconst endpointUrl = new URL('https://api.dropboxapi.com/2/file_requests/delete_all_closed');// Define Header Parameters hereconst headerParameters = {'Authorization': `Bearer ${token}`,'Content-Type': 'application/json',};// Set the API call optionsconst options = {method: 'POST',headers: headerParameters,body : 'null'};// Function to make the API callasync function deleteAllClosedRequests() {try {const response = await fetch(endpointUrl, options);// Custom function for printing the API responseprintResponse(response);} catch (error) {// Custom function for printing the error messageprintError(error);}}// Call function to make the API calldeleteAllClosedRequests();
In the code above, we do the following:
- Line 2: We import the
fetch
library that we need to use in our code fromnode-fetch
. - Line 5: We get the value for
TOKEN
to use for authentication. - Line 8: We define the request URL.
- Lines 11–14: We define the
headers
of thefetch
request. It includes the authorization and the type of content, which isapplication/json
in most cases. - Lines 17–21: We set the API call options.
- Lines 24–34: We create a function to make the API call. It will
try
to get the response and will pass the response to the custom functionprintResponse
; otherwise, it willcatch
the error and will pass it to the custom functionprintError
. - Line 37: We call the function
deleteRequests
to make the API call.
Response fields
The code above will delete the file that we closed in the previous section. The “Closed” tab in the “File requests” section is now empty. Let’s take a look at some of the important response fields in the table below.
Field | Format | Description |
| String | Unique ID of the deleted file request. |
| String | Link to the file request that will now give a 404 error. |
| String | Title of the file request. |
| String | Path to the Dropbox folder where this file request was deleted. |
| String | Description of the file request. |