I'm making a request to find all files belonging to a certain client in a Team Drive.
Based on the answer here, this is the code:
function listFiles (){
var client = 'client'
var teamDriveId = 'id';
var pageToken;
var folders = Drive.Files.list({
corpora: 'teamDrive',
supportsTeamDrives: true,
teamDriveId: teamDriveId,
includeTeamDriveItems: true,
q: "title = 'data'"
});
if (folders.items.length !== 1) {
Logger.log('There is a problem.');
return;
}
var query = "name contains '" + client + // this client only
"' and trashed = false and " + // not in trash
"not mimeType = 'application/vnd.google-apps.folder'"; // no folders
Logger.log(query)
var files, pageToken;
do {
files = Drive.Files.list({
q: query,
maxResults: 100,
pageToken: pageToken,
// required for team drive queries
corpora: 'teamDrive',
supportsTeamDrives: true,
teamDriveId: teamDriveId,
includeTeamDriveItems: true
});
if (files.items && files.items.length > 0) {
for (var i = 0; i < files.items.length; i++) {
var file = files.items[i];
Logger.log('%s (ID: %s) (Modified: %s)', file.title, file.id, file.modifiedDate);
}
}
} else {
Logger.log('No files found.');
}
pageToken = files.nextPageToken;
} while (pageToken);
}
If I do not include the "name contains '" + client'"
portion of the query, it works fine. If I do, it returns an error stating just: "Invalid query".
Looking at the docs, I'm not understand how my syntax differs from the what is specified there.
I've tried multiple variations along these lines:
"name contains 'client' and trashed = false and not mimeType = 'application/vnd.google-apps.folder'"
"trashed = false and not mimeType = 'application/vnd.google-apps.folder' and name contains 'client'"
Any ideas to fix this?