DropBox Paper API Guide for Python

Dropbox Paper API logo

Dropbox Paper API gives your company creative solutions for meeting your unique requirements. Though, you must understand how to program with the framework to reap the rewards. This guide will walk you through the basics. 

What is Dropbox Paper and Its API? 

As an expansion, Dropbox Paper is not a standalone product, and requires an active Dropbox account to use. However, it gives you full control over your documents without third-party solutions from any supported platform. At its heart is the rich media and code snippets you drop into your documents, which include other Dropbox files, Instagram photos, tweets, YouTube videos, SlideShare slides, and much, much more.  

Getting Started with Paper API 

The API itself is already available to your account. You just have to configure it, and you do that by clicking the Paper menu item and then clicking the “Get Started” button. Dropbox will then walk you through the initial setup.  Once you finished the setup, you must create a Paper app to start coding for it. 

You make Paper apps by Selecting “Create App” from the App Console. You need to choose a scope, but otherwise the creation form is pretty basic. A business scope lets your script access to Team and other business account information, while Dropbox just gives you the basics. You also need an access token for the app, but you can get that at any time.  

The Dropbox Python SDK 

While you need an app to start coding, you must use the Dropbox SDK to actually code your scripts. Making sure you got the latest version; you install the SDK from any command prompt with the following command: 

pip install dropbox 

This adds the dropbox namespace and a connection object to your system. Since you need Paper as well, you should start every script as follows: 

import dropbox 
from dropbox.exceptions import ApiError 
from dropbox.paper import ImportFormat, PaperDocCreateError 
dbx = dropbox.Dropbox(‘access token’) 

You just replace “access token” with your app’s token, and you are ready to work with Paper.  

Working with the Paper API 

As of this article, you can only access metadata from the paper files in your Dropbox account. You can also do minor edits and file searches as well.  

Creating and Updating  New files 

Creating and updating files use the same command structure, but with different commands. You create files with the paper_docs_create command. You edit them with paper_docs_upload. If any issues arise from them, you can check them through the PaperDocCreateError opbject.  

content = "<p>Paper file content</p>" 
   r = dbx.paper_docs_create(content, ImportFormat('html')) 
except PaperDocCreateError as e: 
print("PaperDocCreateError ERROR %s" % e) 
except ApiError as e: 
    print("API ERROR %s" % e) 

Searching Files 

The APi only has a basic search function, but it will give you a list of files in your account. .  

for entry in dbx.files_list_folder('').entries:  

Dropbox adds new commands to the API as they go. You can read the Dropbox SDK command guide to see the latest updates. The guide may give you the right inspirations to get you started. 

Leave a Reply

Your email address will not be published. Required fields are marked *