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:
createlistcount
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.
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–13: We define the
headersof thefetchrequest. It includes the authorization and the type of content, which isapplication/jsonin most cases. - Lines 17–22: We define the
bodyParametersof thefetchrequest. - Lines 25–29: We set the API call options.
- Lines 32–42: 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 45: We call the function
fetchRequestto 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:
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–13: We define the
headersof thefetchrequest. It includes the authorization and the type of content, which isapplication/jsonin 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
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 36: We call the function
fetchRequestListto 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.
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–21: We set the API call options.
- Lines 24–33: 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 36: We call the function
fetchTotalRequeststo make the API call.
Response
The code above will return the total file requests specific to the current user.