Skip to content

Can't access existing folder #144

@f0t0n

Description

@f0t0n

Hi guys,

I have some files in my Box folder and I need to do some operations on them, namely download and analyze their content, then map file URLs to entities in my database. So that I've went forward with boxsdk[jwt].
I've set up a code to access an existing folder to read files from.
The URL in Box looks like https://<username>.app.box.com/files/0/f/<int_id>/<folder_name>.
Though when I try to use that int_id as a Folder ID, the response says me that the folder is not found.
Then I tried to get a root folder with ID 0 but it says it's empty.

My code looks like follows:

from boxsdk import Client
from boxsdk import JWTAuth
from functools import partial


BOX_USER_NAME = '<my_box_user_name>'


def box_import(folder_id, client_id, client_secret, jwt_key_id, enterprise_id,
               rsa_private_key):
    create_auth = partial(
        JWTAuth, client_id=client_id, client_secret=client_secret,
        jwt_key_id=jwt_key_id, enterprise_id=enterprise_id,
        rsa_private_key_file_sys_path=rsa_private_key)
    auth = create_auth()
    client = Client(auth)
    users = client.users(filter_term=BOX_USER_NAME)
    user = users[0] if users else client.create_user(BOX_USER_NAME)
    user_auth = create_auth()
    user_auth.authenticate_app_user(user)
    client = Client(user_auth)

    folder = client.folder(folder_id=folder_id).get()
    print(folder.name)
    print(folder.owned_by)
    print(folder.get_items(100))

In result I get next output:

All Files
{'id': '282981125', 'type': 'user', 'login': '<user_login>@boxdevedition.com', 'name': '<my_box_user_name>'}
[]

So the empty list at the end indicates the root folder is empty. But it's not really. I have gigabytes of data in my account.

Why do I see such behavior and how I could access the target folder inside my root folder having its box URL?

User types and scopes in app settings:

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions