box / box-windows-sdk-v2

Windows SDK for v2 of the Box API. The SDK is built upon .NET Framework 4.5

Home Page:https://developer.box.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to use SearchAsync to get a sub-folder ID from its name?

Dave-Lowndes opened this issue · comments

This is what I've tried so far - but it returns no results (the folder name does exist under the parent):

var items = await actor.SearchManager.SearchAsync( limit: 2, ancestorFolderIds: new List<string>() { parentFolderId }, type: "folder", scope: "user_content", keyword: folderName );

What am I doing wrong?

Hi @Dave-Lowndes

I just verified in both .net sdk and raw api level, a call to search folders under a folder is working

Please find below for my example

here is my .net code:
image

here is my raw api call

curl -X GET
'https://api.box.com/2.0/search?query=tmp&type=folder&ancestor_folder_ids=3567150497&scope=user_content'
-H 'authorization: Bearer TOKEN'
-H 'cache-control: no-cache'
-H 'postman-token: 2f854161-1aa1-2210-be69-7fbb859d7107'

image

Not sure why is not working for you, maybe the permission or is a shared folder? I need more context

Thanks @coolboy, I don't know what was wrong when I initially tried this (as I now get results), but I now find that it's returning sub-sub-folders, when I only wanted to get a single immediate child folder of the parent. Is there any way of restricting the search to just the immediate children of the parent?

@coolboy

After more testing, it seems that I'm actually only getting results when performing the search with an admin user - a normal user returns nothing.
Seeing that the same normal user account can get the folder items using FoldersManager.GetFolderItemsAsync (and then enumerate those to find the folder Id that matches the name), this search restriction seems odd, but perhaps understandable depending on it's underlying implementation.
I guess I'll have to stick with the slow FoldersManager.GetFolderItemsAsync method.

@Dave-Lowndes

Sure, and you can find more information here -> https://developer.box.com/reference#searching-for-content

Just updated the link, not sure why it's not working on other token, maybe permission related, did the user has full access to the folder you are trying to search for?

@coolboy,

How does the information you linked relate to SearchAsync?

@Dave-Lowndes

Sorry too many things on my plate and get the wrong link.

See my updated response above, or this maybe internal wrong implementation in search, but I could not tell unless I know your account setup/context

@coolboy
Thanks for the updated link, I see mentioned there a significant limitation I wasn't aware of: "If an item is added to Box then it becomes accessible through the search endpoint after ten minutes."; which wouldn't be appropriate for our use, so I'll give up on it now.

It is unfortunate that there isn't a direct (and one would hope faster) way of getting a folder ID from a folder name than FoldersManager.GetFolderItemsAsync.

@Dave-Lowndes

We are going to have get file/folder by path API coming soon FYI

We are going to have get file/folder by path API coming soon FYI

@coolboy any updates regarding this ?

@Maxwe11 The Get By Path API is not yet stable, but we will be adding it to this SDK when it is released.

@mattwiller is this available, yet?

@Maxwe11 The Get By Path API is not yet stable, but we will be adding it to this SDK when it is released.

@thesimmermon The Get By Path API is still not considered stable, so we're not yet planning to add it to the SDK. We'll add it in shortly after the API is made generally available!

@mattwiller @coolboy Is there any update on if/when the Get By Path API will be available? We have a use case where we have hundreds of thousands of folders in one folder, and need to get the folder id of one of those folders in order to process an upload. Using the search API doesn't work for us because it takes ten minutes for new folders to be indexed, and iterating through folders is taking a long time because of the number of folders to search through. In our tests it's taking upwards of 7 minutes to find the folder we are looking for, which is way too long for our needs (a user would be uploading a small file and waiting upwards of 7 minutes for it to finish, where the actual transfer of the file takes maybe 1 second). We really need a quick way to retrieve a folder id based on the path.

@nicknlsn I am no longer with box, @cbetta do you have any idea? ^^^

Tnx @coolboy, hey @nicknlsn can you drop me an email. We might have some new stuff coming up that you can use here. My username at box.com

ezoic increase your site revenue