Create, List, and Get File Requests
Learn how to create, list, and get the total number of file requests.
In this lesson, we’ll see some important endpoints of the file_requests
namespace. These endpoints require us to enable the file_requests.read
and file_requests.write
permissions. We’ll discuss the following endpoint operations:
create
list
count
Create a file request
We’ll first explore the /file_requests/create
endpoint. It initiates a request to create a file for the user whose access token is being passed in the request’s headers
parameter. This is an HTTP POST
request.
Request parameters
Let’s take a look at some of the important parameters for our request, their descriptions, and their formats in the table below:
Parameter Name | Format | Required | Description |
| String | Yes | Specifies the name of the requested file. |
| String | Yes | Defines the path to the Dropbox folder where we want to create or save a file. Path should be in "/(.|[\r\n])*" format. Applications that have enabled the “App folder” permission will have a path relative to the specified folder. |
| Object | No | Can only be used by professional and business accounts. |
| Boolean | No | Indicates whether this file should be open or not. Submissions can’t be made if the file is closed. It’s set to |
| String | No | Defines the description of the file request. |
Let’s take a look at the code for this endpoint below. When we execute the code, the file ID is automatically extracted. We’ll need this file ID in the next lesson, so let’s click the “Save” button to save 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/create');// Define Header Parameters hereconst headerParameters = {'Authorization': `Bearer ${token}`,'Content-Type': 'application/json',};// Define Body Parameters hereconst bodyParameters = JSON.stringify({title : "demoFileByAPI",destination : "/home",open : true,description : "We used an API call to create this request."});// Set the API call optionsconst options = {method: 'POST',headers: headerParameters,body: bodyParameters,};// Function to make the API callasync function fetchRequest() {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 callfetchRequest();
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–13: We define the
headers
of thefetch
request. It includes the authorization and the type of content, which isapplication/json
in most cases. - Lines 17–22: We define the
bodyParameters
of thefetch
request. - Lines 25–29: We set the API call options.
- Lines 32–42: 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 45: We call the function
fetchRequest
to make the API call.
Response fields
We’ll now go to our Dropbox dashboard and select the “File requests” option from the side menu. Our file request will be available here.
Let’s take a look at some of the response fields in the following table:
Field | Format | Description |
| String | Unique ID of the file. |
| String | URL of our created file; anyone with this link can upload files to our Dropbox. |
| String | Title of the file that we specified in the call. |
| String in format "/(.|[\r\n])*" | Provides the full path to the file (in our case, it’s "/home"). |
| Boolean | Tells us the status of the file, if it’s |
List all file requests
Let’s list all the file requests for a specific user. The /file_requests/list
endpoint requires us to enable the file_requests.read
permission. There are no parameters required to make this call—let’s take a look at the code to see how we can write this request:
// 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/list');// 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 fetchRequestList() {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 callfetchRequestList();
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–13: 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–33: 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 36: We call the function
fetchRequestList
to make the API call.
The successful execution of the code above will return file_requests
, including all the requested files and their properties.
Response fields
Most of the response fields are the same as the ones we’ve discussed previously. Regardless, let’s take a look at some of the important response fields for the list
endpoint in the table below:
Fields | Format | Description |
| string | Unique ID of the file request. |
| boolean | Indicates whether the file request is |
| int | Total number of files that were uploaded using the URL associated with the file request. |
The file ID returned by the list
endpoint can be used to get information about a single file request using the /file_requests/get
endpoint. The file ID will be given in the data
object.
Get the total number of file requests
The /file_requests/count
endpoint of the file_requests
namespace is very straightforward. It doesn’t take any parameters and returns the total number of file requests.
// 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/count');// 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 fetchTotalRequests() {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 callfetchTotalRequests();
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–33: 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 36: We call the function
fetchTotalRequests
to make the API call.
Response
The code above will return the total file requests specific to the current user.