Get User Information

Learn how to get a user's information using the Dropbox API endpoints.

In this lesson, we’ll explore some of the important endpoints of the users namespaceA declarative region that defines the scope of variables, functions, types, and so on.. These endpoints require us to enable the 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.

Press + to interact
import requests
import json
url = "https://api.dropboxapi.com/2/users/get_current_account"
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 1–2: We import the requests and json 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 the HTTP request. It includes the authorization as well as the type of content, which is application/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

account_id

This is the unique ID of the Dropbox account associated with the access token.

String

name

These are the details of the user's name

Object

email

This the user’s email address.

String

email_verified

This indicates if the user's email address has been verified

Boolean

profile_photo_url

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.

Press + to interact
import requests
import json
url = "https://api.dropboxapi.com/2/users/get_space_usage"
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:

  • 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 to None because we are not sending any data with our request.
  • Line 12: We create a POST request with the following parameters: url, headers, and data.
  • 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

used

This is the total amount of storage space used by the user, specified in bytes.

UInt64

allocation

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