1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] Box-api get_items() folders fetch limits to 15 folders

Discussão em 'Python' iniciado por Stack, Outubro 7, 2024 às 09:32.

  1. Stack

    Stack Membro Participativo

    I am trying to fetch a specific folder under thetarget_folder_name variable from my box account using get_items in box SDK. However, my code below fetches only first 15 folder names and stops rightafter. Pagination is not working as expected.

    def lambda_handler(event, context):
    box_client = get_box_jwt_client()
    target_folder_name = "my_test_folder"
    box_folder_id = get_box_folder_id(box_client, target_folder_name)

    if box_folder_id:
    print(f"Found folder ID: {box_folder_id}")
    else:
    print(f"Folder '{target_folder_name}' not found")

    def get_box_folder_id(items, target_folder_name, root_folder_id="0", limit=200, offset=0):
    """
    Recursively fetches items from a Box folder in batches and returns the folder ID of the target folder.
    """
    items = box_client.folder(root_folder_id).get_items(limit=limit, offset=offset)
    for item in items:
    if item.name == target_folder_name and item.type == 'folder':
    print(f"Folder '{target_folder_name}' found with ID: {item.id}")
    return item.id # Return the folder ID as soon as it is found
    if len(list(items)) < limit:
    return None
    # Fetch the next batch by updating the offset
    return get_box_folder_id(box_client, target_folder_name, root_folder_id, limit, offset + limit)


    How to fix the file fetch limit issue?

    Continue reading...

Compartilhe esta Página