Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Downloading from SharedFolder API error Not found items #886

Closed
gosztidj opened this issue Feb 9, 2023 · 11 comments
Closed

Downloading from SharedFolder API error Not found items #886

gosztidj opened this issue Feb 9, 2023 · 11 comments

Comments

@gosztidj
Copy link

gosztidj commented Feb 9, 2023

Hello!

We have a shared link that we want to automatically download from in C#, but when I want to access the contents of the folder, I get the following error:
BoxAPIException: The API returned an error [NotFound | crrdb2haxiqfe5eh.0a252b39d52f3d8f12b6e4c8d0b816a1e] not_found - Not Found

Why can't you find the items in the folder?

            var config = new BoxConfig("CLIENT_ID", "", new Uri("http://localhost"));
            var session = new OAuthSession("ACCESS TOKEN", "N/A", 3600, "bearer");
            var client = new BoxClient(config, session);
            string webLinkUrl = "https://samchully.app.box.com/v/Europe000000";


            var user = client.UsersManager.GetCurrentUserInformationAsync().Result;
            Console.WriteLine($"User: {user.Id}:{user.Name}");
            Task <BoxItem> getsharedItems = client.SharedItemsManager.SharedItemsAsync(webLinkUrl);
            BoxFolder sharedFolder = (BoxFolder)getsharedItems.Result;
            var items = client.CollectionsManager.GetCollectionItemsAsync(sharedFolder.Id, 5000);
            Console.WriteLine(items.Result);

            Console.WriteLine("Id: " + sharedFolder.Id);
@congminh1254
Copy link
Member

Hi @gosztidj,

Thanks for submitting your question, we are checking it and will get back to you ASAP.

Best regards,
Minh

@congminh1254
Copy link
Member

Hi @gosztidj,

I just verified your code, and everything went well, so please verify if the shared link is correct and the user you are authenticating has permission to access the shared link.

If it still isn't working, please let me know.

Thank you.

@gosztidj
Copy link
Author

gosztidj commented Feb 9, 2023

Hi @congminh1254

This link does not require authentication, it is freely available.

What could be the problem?

@congminh1254
Copy link
Member

congminh1254 commented Feb 9, 2023

Hi @gosztidj,

I think you should verify your shared link, it should start with https://username.box.com/s/ but not https://username.app.box.com/v/, it's seem to be unusual, and keep in mind that it should be a shared link which you got from the share dialog or from create shared link function, but not copy it after it's navigating by the browser.

If this would not help reach out to support, they can deeply investigate your shared link to get a better resolution:
https://support.box.com/hc/en-us/requests/new

I hope this can help.

Best regards,
Minh

@gosztidj
Copy link
Author

Hi @congminh1254 ,

Some progress has been made. /v in the link corresponds to viewer.

I tried to run the code with the python BOX SDK and it ran without errors, everything was downloaded from the given folder. The problem is that I would have to do this in a .NET program and it would run into an error.

@congminh1254
Copy link
Member

Hi @gosztidj,

Thanks for your information, can you provide your code with Python SDK and for us to compare, then we will try to figure out what is going wrong :D

Have a nice week.
Minh Nguyen Cong

@gosztidj
Copy link
Author

Hi @congminh1254,

This is working python code:

import os
import datetime
from boxsdk import JWTAuth, Client

def main():
auth = JWTAuth.from_settings_file(settings_file_sys_path='980952769_tidv16ck_config.json')
auth.authenticate_instance()
client = Client(auth)
CurrentDate=datetime.datetime.now()
print (CurrentDate)
web_link_url = "https://samchully.app.box.com/v/Europe000000"

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")

@congminh1254
Copy link
Member

congminh1254 commented Feb 14, 2023

Hi @gosztidj,

Can you try to submit the request manually with CURL with this following instruction Find folder for shared link

curl -i -X GET "https://api.box.com/2.0/shared_items" \
     -H "Authorization: Bearer <ACCESS_TOKEN>" \
     -H "BoxApi: shared_link=https://app.box.com/s/jsasdsd8sad24&shared_link_password=letmein"

The access_token can be found in the Dev Portal.

@gosztidj
Copy link
Author

Hi @congminh1254 ,

The folder_id was determined, the problem is that it does not return, or the ItemCollection is null and therefore the error is 404.

image

@congminh1254
Copy link
Member

Hi @gosztidj,

I got your case. We identified the bug and will fix it as soon as possible, once again, thanks for your patience. I will let you know when the bug is fixed.

Have a nice day.

Thank you.

@mwwoda
Copy link
Contributor

mwwoda commented Feb 27, 2023

The missing fields were added in #892. It should be shipped soon with the new version of the SDK.

You can get items from folder with SharedLink by calling GetFolderItemsAsync on FoldersManager with shared link and optionally with a password.

            // we need to have a sharedLink
            var sharedLink = await boxClient.FoldersManager.CreateSharedLinkAsync(folder.Id, sharedLinkRequest);

            // we need to get folderId somehow
            var sharedItems = await boxClient.SharedItemsManager.SharedItemsAsync(sharedLink.SharedLink.Url, password);

            var items = await boxClient.FoldersManager.GetFolderItemsAsync(sharedItems.Id, 100, sharedLink: sharedLink.SharedLink.Url,
                sharedLinkPassword: password);

@mwwoda mwwoda closed this as completed Feb 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants