Successfully get folder ID of public shared folder, but can't get items, ID in message has d_ prefix

I’m trying to download the files of the publicly shared KUL fall simulation dataset (Box), as I access the server I want to run my AI training on via ssh and of course don’t have a browser there. Also I’d like to avoid copying 20GB of videos via ssh or something.

My app successfully authenticates and obtains the folder ID from the shared link using client.get_shared_item(shared_link), it returns “44028703597” as the folder ID.

Then I call folder_items = client.folder(folder_id).get_items(), no problems here.

Now when I try to iterate over that, I get an error message that the folder with the ID “d_44028703597” can’t be found, which is weird because in the same message I can see that the SDK calls GET https://api.box.com/2.0/folders/44028703597/items?offset=0, without the d_ prefix.

Any idea what I’m doing wrong? My app has read permission, I can’t see anything else it might need to read public files.

Hi ! Welcome to the Forum @Metallkiller !

I checked our logs, and I can confirm this is due to a permissions issue. We have this error :

message=Missing+permissions+item_view&d_44028703597%5Bitem_view%5D=permission+not+granted&box_parameter_with_permission_failure%5B0%5D=folder

It means that the user doing the API call doesn’t have the permissions accessing the files.

Hi, thanks for checking! The files are shared publicly and I can even download them via browser without any login, then how can the user not have permission to download them? Or do I need a different endpoint for shared files?

Yes, indeed.
Only the owner or collaborators can access the folder endpoint.
Given that you’re trying access the folder with another account, it won’t work.

To access the files, you need to be a collaborator on the folder.

Then which endpoint should I use to get the files (or download the zip) via the shared link? I can’t find a fitting endpoint in the API reference.

If you need the File ID you can use the Shared Link endpoint :

If you have the File ID, you can use the Download endpoint :

Hi @Metallkiller, welcome to the forum.

Following up on this thread, looks like Kuleuven might have updated their security settings, and I was able to come up with a python script, as an example, that will download each file:

"""demo to download files from a box web link"""
import os
from boxsdk import JWTAuth, Client


def main():
    auth = JWTAuth.from_settings_file('.jwt.config.json')
    auth.authenticate_instance()
    client = Client(auth)

    web_link_url = "https://kuleuven.app.box.com/s/dyo66et36l2lqvl19i9i7p66761sy0s6"

    user = client.user().get()
    print(f"User: {user.id}:{user.name}")

    shared_folder = client.get_shared_item(web_link_url,'' )
    print(f"Shared Folder: {shared_folder.id}:{shared_folder.name}")
    print("#" * 80)

    print("Type\tID\t\tName")
    os.chdir('downloads')
    items = shared_folder.get_items()
    download_items(items)
    os.chdir('..')

def download_items(items):

    for item in items:
        if item.type == 'folder':
            os.mkdir(item.name)
            os.chdir(item.name)
            download_items(item.get_items())
            os.chdir('..')

        if item.type == 'file':
            print(f"{item.type}\t{item.id}\t{item.name}",end='')
            with open(item.name,'wb') as download_file:
                item.download_to(download_file)
            print("\tdone")


if __name__ == "__main__":
    main()
    print("Done")

Which resulted in:

User: 20344589936:UI-Elements-Sample
Shared Folder: 44028703597:Fall_Simulation_Data
################################################################################
Type    ID              Name
file    261422972029    ADL10_Cam1.avi  done
file    261425259417    ADL10_Cam2.avi  done
file    261426893160    ADL10_Cam3.avi  done
file    261427013993    ADL10_Cam4.avi  done
file    261428355921    ADL10_Cam5.avi  done
file    261432107784    ADL11_Cam1.avi  done
file    261432109936    ADL11_Cam2.avi

Due to the number of files, you’ll probably need to adapt the script to check if the file has already been completely downloaded, just in case it fails or you want to do this in chunks.

Let us know if this helps.

I was using the classic Python SDK and JWT authorization.

Cheers

Great this works, thanks a lot!