cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
If you're up against the clock to get holiday ready, so here are some tips on how to use Dropbox to make your prep easy! Check them out!

Discuss Dropbox Developer & API

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Problems using Dropbox Javascript SDK with API filesSearchV2

Problems using Dropbox Javascript SDK with API filesSearchV2

tfrysinger
Explorer | Level 4

I am using a root folder to temporarily store files in what could be thousands of sub-folders under that root. I want to write a routine that would run daily from my website to "clean out" folders that are more than 30 days old. I have been able to get the Dropbox NPM module integrated and can call Dropbox via the Javascript API, but I'm seeing some odd results, and also am not sure the best way to go about efficiently finding the folders I need to delete each day.

 

Here the relevant part of the code that runs on the website:

 

const { Dropbox } = require('dropbox');
// Get DB access token
let token = await getSecret("dbat");
// Get folder for items
let xferfolder = "/" + await getSecret("dbpx");
// Get a dropbox object
let dbx = new Dropbox({ accessToken: token, fetch: fetch });
// Find 'files' (these will all be folders) to review
results = await dbx.filesSearchV2({"query": "pending_", 
                                   "options": {"path": xferfolder},
                                   "match_field_options":{".tag":"filename"}});
 
One of the first things I noticed, was in the metadata returned to me it appears that the match was not done on filename as I requested in my match_field_options, but instead on filename_and_content:
 
"match_type": {".tag":"filename_and_content"},
               "metadata": {".tag": "metadata",
                            "metadata": {".tag":"folder",
                                         "id":"id:mnOYyqkJ95AAAAAAAAAsVw",
                                         "name":"pending_20210304_frysingertad_at_gmail",                                        "path_display":"/PendingSITXfers/pending_20210304_frysingertad_at_gmail",
                        "path_lower":"/pendingsitxfers/pending_20210304_frysingertad_at_gmail"}
                            }
 
Also, I noticed that folders do not have a 'last updated time' property, so I am not sure how I can find the folders which were created or updated more than 30 days ago, without examining each one every time and looking at the metadata of the files within the folder. I tried to come up with a folder naming scheme that would help in this regard - prefixing each folder with 'pending_' so I can use that as the search value, then a date of YYYYMMDD, but there does not seem to be a way to indicate a sort order on the return values? If there were I could then request the oldest be returned first and just loop through these until I reach a folder name that is < 30 days from today and then stop the loop. But alas, there doesn't seem to be a way to do this.
 
Can anyone suggest a better approach to programmatically finding all sub-folders within a directory that were created/last updated more than 30 days ago?
 
Thanks!
1 Reply 1

Re: Problems using Dropbox Javascript SDK with API filesSearchV2

Greg-DB
Dropboxer

To restrict search result to matching on the filename and not content, you should set FilesSearchOptions.filename_only to true. (By the way, your match_field_options doesn't look set correctly. That takes a FilesSearchMatchFieldOptions which only has a boolean include_highlights property.)

 

Anyway, the Dropbox API does not offer a modified time for folders, but I'll pass this along as a feature request. I can't promise if or when that might be implemented though.

 

Likewise, FilesSearchOrderBy currently does not support ordering by name, but we'll consider that a feature request as well.

 

Apologies I don't have better news for you!

Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropboxer
What do Dropbox user levels mean?
Need more support?