Dropbox share with users
This integration automates the process of sharing Dropbox folders with ONLYOFFICE Apps users.
How it works
- Retrieve ONLYOFFICE Apps users - Fetches a list of users with names and emails from ONLYOFFICE Apps.
- Create Dropbox folders - Each ONLYOFFICE Apps user gets a dedicated folder in the Dropbox.
- Share Dropbox folders - Generates a Dropbox shared link for each ONLYOFFICE Apps user.
Full example
import dropbox, requests
# Dropbox API credentials
DROPBOX_ACCESS_TOKEN = 'your_dropbox_access_token'
dbx = dropbox.Dropbox(DROPBOX_ACCESS_TOKEN)
# ONLYOFFICE API credentials
ONLYOFFICE_API_HOST = 'yourportal.onlyoffice.com'
ONLYOFFICE_API_KEY = 'your_onlyoffice_api_key'
# Headers for ONLYOFFICE authentication
ONLYOFFICE_HEADERS = {
'Accept': 'application/json',
'Authorization': f'Bearer {ONLYOFFICE_API_KEY}',
'Content-Type': 'application/json'
}
# Step 1: Retrieve ONLYOFFICE Apps users
def get_docspace_users():
url = f'https://{ONLYOFFICE_API_HOST}/api/2.0/people'
response = requests.get(url, headers=ONLYOFFICE_HEADERS)
if response.status_code == 200:
return [{'name': user['firstName'], 'email': user['email']} for user in response.json()['response']]
print(f'Failed to retrieve ONLYOFFICE Apps users: {response.status_code} - {response.text}')
return []
# Step 2: Create a Dropbox folder for each ONLYOFFICE Apps user
def create_dropbox_folder(user_name, user_email):
folder_path = f'/DocSpace_users/{user_name.replace(" ", "_")}'
try:
dbx.files_create_folder_v2(folder_path)
print(f'Folder created: {folder_path}')
return folder_path
except dropbox.exceptions.ApiError as e:
print(f'Failed to create folder for {user_name}: {e}')
return None
# Step 3: Share the Dropbox folder with the user
def share_dropbox_folder(folder_path, user_email):
try:
shared_link_metadata = dbx.sharing_create_shared_link_with_settings(folder_path)
print(f'Folder shared with {user_email}: {shared_link_metadata.url}')
except dropbox.exceptions.ApiError as e:
print(f'Failed to share folder with {user_email}: {e}')
if __name__ == '__main__':
docspace_users = get_docspace_users()
for user in docspace_users:
folder = create_dropbox_folder(user['name'], user['email'])
if folder:
share_dropbox_folder(folder, user['email'])
Before you start
-
Replace
your-docspace.onlyoffice.comandyour_onlyoffice_api_keywith your actual ONLYOFFICE Apps portal host and API key. Ensure you have the necessary permissions to perform user operations. -
Before you can make requests to the API, you need to create an ONLYOFFICE Apps API key. Check out the API keys article to learn how to obtain and use API keys.
-
Create a Dropbox App with
files.content.writeandsharing.writepermissions. -
Replace
your_dropbox_access_tokenwith your actual Dropbox token. -
Install the Dropbox Python SDK:
pip install dropbox
Step 1: Retrieve ONLYOFFICE Apps users
Use a GET /api/2.0/people request to retrieve each user's first name and email.
# Step 1: Retrieve ONLYOFFICE Apps users
def get_docspace_users():
url = f'https://{ONLYOFFICE_API_HOST}/api/2.0/people'
response = requests.get(url, headers=ONLYOFFICE_HEADERS)
if response.status_code == 200:
return [{'name': user['firstName'], 'email': user['email']} for user in response.json()['response']]
print(f'Failed to retrieve ONLYOFFICE Apps users: {response.status_code} - {response.text}')
return []
if __name__ == '__main__':
docspace_users = get_docspace_users()
Step 2: Create shared Dropbox folders
Use the Dropbox SDK files_create_folder_v2 method to generate a Dropbox folder for each ONLYOFFICE Apps user.
# Step 2: Create a Dropbox folder for each ONLYOFFICE Apps user
def create_dropbox_folder(user_name, user_email):
folder_path = f'/DocSpace_users/{user_name.replace(" ", "_")}'
try:
dbx.files_create_folder_v2(folder_path)
print(f'Folder created: {folder_path}')
return folder_path
except dropbox.exceptions.ApiError as e:
print(f'Failed to create folder for {user_name}: {e}')
return None
if __name__ == '__main__':
docspace_users = get_docspace_users()
for user in docspace_users:
folder = create_dropbox_folder(user['name'], user['email'])
Step 3: Share the Dropbox folder with the user
Use the Dropbox SDK sharing_create_shared_link_with_settings method to share Dropbox folders with ONLYOFFICE Apps users.
# Step 3: Share the Dropbox folder with the user
def share_dropbox_folder(folder_path, user_email):
try:
shared_link_metadata = dbx.sharing_create_shared_link_with_settings(folder_path)
print(f'Folder shared with {user_email}: {shared_link_metadata.url}')
except dropbox.exceptions.ApiError as e:
print(f'Failed to share folder with {user_email}: {e}')
if __name__ == '__main__':
docspace_users = get_docspace_users()
for user in docspace_users:
folder = create_dropbox_folder(user['name'], user['email'])
if folder:
share_dropbox_folder(folder, user['email'])