User Information
Learn how to get user information, such as account detail and space usage, using Dropbox API.
We'll cover the following...
In this lesson, we’ll explore some of the important endpoints of the users namespace. These endpoints require us to enable the account_info.read permission. We’ll interact with the following endpoints in this lesson:
get_current_accountget_space_usage
Note: We granted permission for
account_info.readin the previous lesson after we generated our access token.
Get current account details
The users namespace offers the following endpoint:
/users/get_current_account.
We can use this endpoint to retrieve a user’s information with the access token. This endpoint requires Bearer authorization, which 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:
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–20: We set the API call options.
- Lines 23–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 pass it to the custom functionprintError. - Line 36: We call the function
fetchAccountto make the API call.
Response fields
Some of the important fields from the response are shown in the table below.
Fields | Format | Description |
| String | Unique ID of the Dropbox account associated with the access token. |
| Object | Details of the user's name. |
| String | User’s email address. |
| Boolean | Indicates if the user's email address has been verified. |
| String | URL (link) of the user's profile photo (if one has been uploaded). |
Get details about space usage
The endpoint /users/get_space_usage doesn’t take any parameters and returns the status of the storage space allocated to and used by the user.
Take a look at the code below to get more information about the user’s space usage:
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–20: We set the API call options.
- Lines 23–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
fetchStorageto make the API call.
Response fields
Let’s take look at the various response fields for our space usage query in the following table:
Field | Format | Description |
| UInt64 | Total amount of storage space used by the user (specified in bytes). |
| Object | Total storage space quota allocated to the user. Space allocation consists of two types, individual and team (in our case, it’s individual). |