0

I have an function in Google Apps Script that should list files from yesterday. I want to filter them out upon request as there are many files and I only need the 'latest' ones.

I added the Google Drive API v2 (v3 is not available) in Services for the project.

This code fails:

function getFiles(){
  let query = "trashed = false and mimeType = 'application/vnd.google-apps.document' and 
  createdTime > '2023-03-22T00:00:00.00'";

  let files = Drive.Files.list({
    useDomainAdminAccess: true,
    corpora: "drive",
    driveId: "<drive id here>",
    includeItemsFromAllDrives: true,
    supportsAllDrives: true,
    q: query  
  });
}

With error message:

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

I checked the documentation at https://developers.google.com/drive/api/guides/ref-search-terms, and createdTime is available for v2 (at least it looks like it is available).

Is there something wrong with my query? Incorrect date format? Syntax error? Or is createdTime not available in Drive v2 API?

Btw this work if I remove createdTime from the query.

Paul
  • 61
  • 5
  • I thought that this answer might be an answer to your question. https://stackoverflow.com/q/74114388 – Tanaike Mar 23 '23 at 11:11
  • Thanks @Tanaike. That helped mo solve the problem. In addition to the post, I had to check out [this](https://stackoverflow.com/questions/45534493/using-authtoken-obtained-via-scriptapp-getauthtoken-to-call-web-apps-in-gas) to authorize the request to the API. – Paul Mar 24 '23 at 00:34

0 Answers0