Hello, I have a question about the box API when OAuth 2.0 is used. My end goal is to upload a file to box using a bot. The first part of my test is to set up the API and do this manually for now.
With this goal in mind, I created a personal box account (my organization suggested doing this) to do testing. Then, I created an application and followed the instructions from box to authenticate using Python and SDK.
The problem that I’m facing is that I cannot view my root folder. I get a message saying <Box Folder - 0 (All Files)>. I can create folders, search for files, and upload file to box root folder.
I read some of the posts on the forum and I already discarded the possibility that I am using a service account because when I look at my client.user() i see my user ID and email. Also, I’m using a developer token and to my understanding, a developer token is associated with the user who’s logged into the developer console. The code that I’m using is below, thank you!
from boxsdk import OAuth2, Client
auth = OAuth2(
client_id='MY_CLIENT_ID...',
client_secret='MY_CLIENT_SECRET...,
access_token='rC2TetewQsKzZxCz2gVdM0VbLDcD1NcZ'
)
auth_url, csrf_token = auth.get_authorization_url('https://developer.box.com/auth/callback')
# redirect(auth_url, code=302)
client = Client(auth)
#I get my user
user = client.user().get()
print(f'\n\nThe current user is \n{user}\n\n')
#can not get the root folder
root_folder = client.root_folder().get()
print("the root folder is ",root_folder)
#But I can send files to the root folder, create folders, do query searches etc
folder_id = '0'
new_file = client.folder(folder_id).upload('test.pdf')
print(f'File "{new_file.name}" uploaded to Box with file ID {new_file.id}')