This project contains workshops on how to use the Box Python SDK to interact with the Box API.
- Create a Box free account if you don't already have one.
- Complete the registration process for a Box developer account.
- Making sure you're logged in navigate to the Box Developer Console. This will activate your developer account.
- Create a new Box application. Select Custom App, fill in the form and then click Next.
- Select User Authentication (OAuth 2.0) and then click Create App.
- Scroll down to Redirect URIs and add the following redirect URI:
- http://127.0.0.1:5000/callback
- (or whatever you have configured in the .env file)
- Check all boxes in application scopes.
- (or only what you think will be necessary)
- Click Save Changes.
- Note the Client ID and Client Secret. You will need these later.
git clone [email protected]:box-community/box-python-gen-workshop.git
cd box-python-gen-workshop
python3 -m venv .venv
source .venv/bin/activate
pip install --upgrade pip
pip install -r requirements.txt
cp sample_oauth.env .oauth.env
python3 -m venv .venv
.venv\Scripts\activate.bat
pip install --upgrade pip
pip install -r requirements.txt
python3 -m venv .venv
.venv\Scripts\Activate.ps1
pip install --upgrade pip
pip install -r requirements.txt
copy sample_oauth.env .oauth.env
code .
Update the CLIENT_ID and CLIENT_SECRET field values in the env file with the Box application client id and client secret you created on the developer console. Depending on the workshop you are working on, you may need to update other environment variables in the .env file.
# Common settings
CLIENT_ID = YOUR_CLIENT_ID
CLIENT_SECRET = YOU_CLIENT_SECRET
# OAuth2 settings
CALLBACK_HOSTNAME = 127.0.0.1
CALLBACK_PORT = 5000
REDIRECT_URI = http://127.0.0.1:5000/callback
Depending on the type of authentication you'll be using test the associated files.
python test_oauth.py
The first time you run the application, it should open a web browser window and prompt you to log in to Box. After you log in, it will ask you to authorize the application. Once this process is complete you can close the browser window. By default the sample app prints the current user's name to the console, and lists the items on the root folder.
The authorization token last for 60 minutes, and the refresh toke for 60 days. If you get stuck, you can delete the .oauth.tk.db file and reauthorize the application.
JWT or CCG authentication will not require you to log in to Box.
If you get stuck or have questions, make sure to ask on our Box Developer Forum
You'll find the workshop exercises in the workshops folder.
- Folders - List, recursion, create, update, rename, copy, error handling, and delete
- Files - Upload, download, update, move, copy, error handling, and delete
- File Comments - Interact with the activity feed and comments
- File Collaboration - Create and manage collaborations
- File Requests - Create and manage file requests
- Search - Using search in the Box API
- Shared Links - Create and manage shared links
- File Representations - Working with file representations
- Sign - Unstructured documents - Working with Sign, and simple documents. Includes most features of the Sign request.
- Sign Templates - Working with Sign Templates.
- Sign Structured documents - Working with Sign Structured documents.
- Tasks - Working with Tasks.
- Users - Working with Users.
- Groups - Working with Groups.
- Watermark - Working with Watermark.
- Box AI - Working with Box AI.
- Box AI Extract - Extracting structured data from documents using Box AI.
- Metadata - Working with Metadata.