Get User Information
Learn how to get a user's information using the Dropbox API endpoints.
We'll cover the following
In this lesson, we’ll explore some of the important endpoints of the users
account_info.read
permission. We’ll interact with the following endpoints in this lesson:
get_current_account
get_space_usage
Note: We granted permission for
account_info.read
in the previous lesson after we generated our access token.
Get current account details
The users
namespace offers the following endpoint:
/users/get_current_account
.
It’s used to retrieve a user’s information with the access token. It uses Bearer
authorization and is defined in the header of the HTTP request. It utilizes an HTTP POST
request and doesn’t take any parameters.
Let’s see this endpoint’s functionality in the code below.
import requestsimport jsonurl = "https://api.dropboxapi.com/2/users/get_current_account"headers = {"Authorization": "Bearer {{TOKEN}}","Content-Type": "application/json"}data = Noner = 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 1–2: We import the
requests
andjson
libraries that we need to use in our code. - Line 4: This is the URL we need to call.
- Lines 6–9: We define the
headers
of theHTTP
request. It includes the authorization as well as the type of content, which isapplication/json
in most cases. - Line 11: This is the request’s data, which is set to
None
for this specific API call. - Line 12: We create the
POST
request. - Line 13: We print the response.
Response fields
Some of the important fields from the response are shown in the table below.
Fields | Description | Format |
| This is the unique ID of the Dropbox account associated with the access token. | String |
| These are the details of the user's name | Object |
| This the user’s email address. | String |
| This indicates if the user's email address has been verified | Boolean |
| This is the URL (link) of the user's profile photo (if one has been uploaded). | String |
Get details about space usage
The endpoint /users/get_space_usage
doesn’t take any parameters and returns the status of the storage space that’s allocated to and used by the user.
Let’s take a look at the code below to get more information about the user’s space usage.
import requestsimport jsonurl = "https://api.dropboxapi.com/2/users/get_space_usage"headers = {"Authorization": "Bearer {{TOKEN}}","Content-Type": "application/json"}data = Noner = 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:
- Line 4: This is the URL used for the request.
- Lines 6–9: We define the
headers
object. - Line 11: We define the
data
object, which is set toNone
because we are not sending any data with our request. - Line 12: We create a
POST
request with the following parameters:url
,headers
, anddata
. - Line 13: We print the
json
formatted response.
Response fields
Let’s take a look at the various response fields for our space usage query in the following table.
Field | Description | Format |
| This is the total amount of storage space used by the user, specified in bytes. | UInt64 |
| This is the total storage space quota allocated to the user. Space allocation consists of two types, individual and team. In our case, it’s individual. | Object |