Searching with API with multiple Ancestor_Folder_IDs
I'm using python and the Box API to search and am trying to include 2 folders in my 'ancestor_folder_ids' parameter. The documentation implies you can enter multiple IDs, but none of my testing has shown this to work. The search result only includes the last folder in the ancestor_folder_ids = [oppty_folder_id,account_folder_id] list. I've swapped the folders in the =[....] list and it always returns only the last one listed.
How do I get the search to include both folders? Is my syntax below incorrect?
oppty_folder_id = "5***phone number removed for privacy***"
account_folder_id = "6***phone number removed for privacy***"
items = client.search().query(query='test',
limit=1000,
ancestor_folder_ids=[oppty_folder_id,account_folder_id],
file_extensions=['pdf'],
type=['file'],
fields=['id','type','modified_at','name','parent','path_collection']
)
-
Hi ,
I took a look at the query method for the Python SDK and it looks like they're using "ancestor_folders" instead of "ancestor_folder_ids" as a param, then joining whatever is passed there into the API call using ancestor_folder_ids.
Can you try swapping ancestor_folder_ids for ancestor_folders and see if that helps?
- Jon
-
I tried changing the search parameter from "ancestor_folder_ids" to "ancestor_folders" and had no luck. The BoxSDK generated an error on line 276 of the search.py when trying to obtain the object_id of the folder that was passed (see screenshot). I tried passing one folder and then again with 2 folders; same result.
See the source code below showing the call to the search API that is generating the error. I get the same error if I change the search API call with 2 folders "ancestor_folders=[account_folder_id,oppty_folder_id]" to call only 1 folder - "ancestor_folders=[account_folder_id]".
oppty_folder_id = "21075437786" account_folder_id = "7***phone number removed for privacy***" def process_files(search_folder): if search_folder == "account": this_folder = account_folder_id else: this_folder = oppty_folder_id box_items = client.search().query(query='coi', limit=1000, ancestor_folders=[account_folder_id,oppty_folder_id], file_extensions=['pdf'], type=['file'], fields=['id', 'type', 'modified_at', 'name', 'parent', 'path_collection'] ) ......
See the screenshots below for the error message generated, and the debug listing showing the variable values when 1 or 2 folders are passed to the API.
You really should update the Box API search documentation to state that the correct parameter is "ancestor_folders" and not "account_folder_ids". In debugging the API calls, when the search parameter is "ancestor_folder_ids=[xxxxx]", the SDK determines that the parameter is empty because nothing is passed with "ancestor_folders".
Please sign in to leave a comment.
Comments
2 comments