Box Search returning all files - Node.js sdk
I am using the node.js sdk to search for a folder but instead of getting that folder(or substring match), the search query is returning all folders for my account. If I specify ancestor_folder_ids, I get all the folders under it.
So the problem is that the filter is not working. I have used quotes as well around the foldername What could I be doing wrong?
var result = await client.search.query(
'', {
type: 'folder',
fields: 'name',
limit: 10,
offset: 0,
ancestor_folder_ids: '12345678'
}
-
To try and get an exact match on a specific folder name, here's what I would suggest doing:
var folderName = 'PUT_FOLDER_NAME_HERE'; var parentFolderID = 'PUT_PARENT_FOLDER_ID_HERE'; var searchOptions = { ancestor_folder_ids: parentFolderID, content_types: 'name', type: 'folder', }; var query = '"' + folderName + '"'; // Use quoted query to get exact matches only var results = await client.search.query(query, searchOptions); var folder = results.entries.find(f => f.name === folderName && f.parent.id === parentFolderID); // `folder` should point to the exact folder you're looking for
Please sign in to leave a comment.
Comments
1 comment