Update and Delete a File Request

Learn how to update and delete a file request.

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.

Press + to interact
// Define import libraries here
import fetch from 'node-fetch';
// Define API key here
const token = '{{TOKEN}}'
// Define endpoint URL here
const endpointUrl = new URL('https://api.dropboxapi.com/2/file_requests/update');
// Define Header Parameters here
const headerParameters = {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json',
};
// Define Body Parameters here
const bodyParameters = JSON.stringify({
id: "{{FILE_ID}}",
title: "Let's modify demoFileByAPI",
open: false
});
// Set the API call options
const options = {
method: 'POST',
headers: headerParameters,
body: bodyParameters,
};
// Function to make the API call
async function callUpdateRequest() {
try {
const response = await fetch(endpointUrl, options);
// Custom function for printing the API response
printResponse(response);
} catch (error) {
// Custom function for printing the error message
printError(error);
}
}
// Call function to make the API call
callUpdateRequest();

In the code above, we do the following:

  • Line 2: We import the fetch library that we need to use in our code from node-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 the fetch request. It includes the authorization and the type of content, which is application/json in most cases.
  • Lines 17–21: We define the bodyParameters of the fetch request. These include the id and title of the request. The open parameter defines whether or not the file request should be open. If the file request is closed, 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 function printResponse; otherwise, it will catch the error and will pass it to the custom function printError.
  • 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.

Press + to interact
// Define import libraries here
import fetch from 'node-fetch';
// Define API key here
const token = '{{TOKEN}}'
// Define endpoint URL here
const endpointUrl = new URL('https://api.dropboxapi.com/2/file_requests/delete_all_closed');
// Define Header Parameters here
const headerParameters = {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json',
};
// Set the API call options
const options = {
method: 'POST',
headers: headerParameters,
body : 'null'
};
// Function to make the API call
async function deleteAllClosedRequests() {
try {
const response = await fetch(endpointUrl, options);
// Custom function for printing the API response
printResponse(response);
} catch (error) {
// Custom function for printing the error message
printError(error);
}
}
// Call function to make the API call
deleteAllClosedRequests();

In the code above, we do the following:

  • Line 2: We import the fetch library that we need to use in our code from node-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 the fetch request. It includes the authorization and the type of content, which is application/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 function printResponse; otherwise, it will catch the error and will pass it to the custom function printError.
  • 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

id

String

Unique ID of the deleted file request.

url

String

Link to the file request that will now give a 404 error.

title

String

Title of the file request.

destination

String

Path to the Dropbox folder where this file request was deleted.

description

String

Description of the file request.