Create, List, and Get File Requests

Learn how to create, list, and get the total count of file requests.

In this lesson, we’ll see some of the 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, so let’s see its parameters in the table below.

Request parameters

The various parameters required for a request are outlined in the table below.

Parameter Name

Description

Format

Required

title

This specifies the name of the requested file.

String

Yes

destination

A destination defines the path to the Dropbox folder where we want to create or save a file. The path should be in "/(.|[\r\n])*" format. Additionally, applications that have enabled the “app folder” permission will have a path relative to the specified folder.

String

Yes

deadline

This field can only be used by professional and business accounts

Object

No

open

This indicates whether this file should be open or not. Submissions can’t be made if the file is closed. It’s set to True by default.

Boolean

No

description

This defines the description of the file request.

String

No

Let’s see 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.

Press + to interact
import requests
import json
url = "https://api.dropboxapi.com/2/file_requests/create"
headers = {
"Authorization": "Bearer {{TOKEN}}",
"Content-Type": "application/json"
}
data = {
"title": "demoFileByAPI",
"destination": "/home",
"open": True,
"description": "We used an API call to create this request."
}
r = requests.request("POST",url, headers=headers, data=json.dumps(data))
print(json.dumps(r.json(), indent=4))

In the code above, we see the following:

  • Lines 4 and 6–9: We specify the url and headers parameters needed for our request, respectively.
  • Lines 11–16: We specify the data needed to create the file request.
  • Line 12: We define the title, which is the name of the requested file.
  • Line 13: We show the destination of the requested file.
  • Line 14: We indicate that the file’s status is currently open.
  • Line 15: We get the description of the file request.
  • Line 18: We define the HTTP request.
  • Line 19: We print the response.

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

Description

Format

id

This is the unique ID of the file.

String

url

This is the URL of our created file. Anyone with this link can upload files to our Dropbox.

String

title

This is the title of the file that we specified in the call.

String

destination

This provides the full path to the file. In our case, it’s "/home."

String in format "/(.|[\r\n])*"

is_open

This tells us the status of the file, if it’s open or closed. If the file is closed, then content can’t be uploaded to it.

Boolean

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.

Press + to interact
import requests
import json
url = "https://api.dropboxapi.com/2/file_requests/list"
headers = {
"Authorization": "Bearer {{TOKEN}}",
"Content-Type": "application/json"
}
data = None
r = requests.request("POST",url, headers=headers, data=json.dumps(data))
print(json.dumps(r.json(), indent=4))

In the code above, we see the following:

  • Lines 4 and 6–9: We specify the url and headers parameters needed for our request, respectively.
  • Line 11: We specify the data value. In this case, it’s None.
  • Line 12: We define the HTTP request.
  • Line 13: We print the response.

The successful execution of the code above will return file_requests, which will include all the requested files along with 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

Description

id

This is the unique ID of the file request.

is_open

This indicates whether the file request is open or closed.

file_count

This is the total number of files that were uploaded using the URL associated with the file request.

The file ID that is 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 amount 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 amount of file requests.

Press + to interact
import requests
import json
url = "https://api.dropboxapi.com/2/file_requests/count"
headers = {
"Authorization": "Bearer {{TOKEN}}",
"Content-Type": "application/json"
}
data = None
r = requests.request("POST",url, headers=headers, data=json.dumps(data))
print(json.dumps(r.json(), indent=4))

Response

The code above will return the total amount of file requests specific for the current user.