How to use the properties query with Drive.Files.List in Google Apps Script v5

88 Views Asked by At

I'm trying to use the Advanced Google Drive service in Google Apps Script to find files with a given custom property value

Drive.Files.list({
          "corpora": "allDrives",
          "includeTeamDriveItems": true,
          "q": "'1tfT0BtCg2Z7B7dviOqNQsZTdSjrX5V9B' in parents and trashed = false and properties has {key='photoId' and value='AJHPqhQHfoNqbZSdk8ZUU-RILziCVXViIWPKBG46RIcTVSqzijyVOwyvk1hRE-PxCv3LGXlcT7e7AacOUjKxrUdnG6ssS4YdnQ'}",
          "supportsTeamDrives": true
        })`

This code as written gives the error

API call to drive.files.list failed with error: Invalid query

however if I remove and properties has {...} it will run fine.

I think I need to escape the curly braces somehow however I can't quite figure out how to do so?

Any help is much appreciated!

1

There are 1 best solutions below

1
TheMaster On BEST ANSWER

visibility parameter is not optional in v2. Use

`
'1tfT0BtCg2Z7B7dviOqNQsZTdSjrX5V9B' in parents and
 trashed = false and
 properties has {
    key='photoId' and 
    value='AJHPqhQHfoNqbZSdk8ZUU-RILziCVXViIWPKBG46RIcTVSqzijyVOwyvk1hRE-PxCv3LGXlcT7e7AacOUjKxrUdnG6ssS4YdnQ' and 
    visibility='PRIVATE'
 }
`