title: How to filter Google Drive API v3 mimeType?
body: <p>I wrote a script that uses DriveApp to read Google Drive, SpreadsheetApp to log data in Sheets, and Google Drive API v3  + service account + OAuth to make changes on behalf of G Suite users.</p>
  
  <p>It would be nice to search Google Drive from the target user perspective (calling Google Drive API v3) instead of the account running the script (calling DriveApp). I can't get the filter to work.</p>
  
  <p>The query is built with parent folder keys, <code>mimeType =</code> or <code>mimeType !=</code> for folders, and is passed into the function. The format is:</p>
  
  <pre><code>var query = "('GoogleDriveFolderKey01' in parents or 'GoogleDriveFolderKey02' in parents) and trashed = false and mimeType = 'application/vnd.google-apps.folder'"
  </code></pre>
  
  <p>The DriveApp function uses:</p>
  
  <pre><code>files = Drive.Files.list({
    q: query,
    maxResults: 100,
    pageToken: pageToken
  });
  </code></pre>
  
  <p>The Google Drive API v3 function uses:</p>
  
  <pre><code>var url = 'https://www.googleapis.com/drive/v3/files/'
  var options = {
    'contentType': 'application/json',
    'method'     : 'get',
    'headers'    : { Authorization: 'Bearer ' + service.getAccessToken() },
    'muteHttpExceptions': true,
    'corpora'    : 'domain',
    'q'          : query,
    'spaces'     : 'drive',
    'pageSize'   : 100,
    'pageToken'  : pageToken
  };
  var response = UrlFetchApp.fetch(url, options);
  
  var resultParsed = JSON.parse(response.getContentText());
  files = resultParsed.files
  pageToken = resultParsed.pageToken
  </code></pre>
  
  <p>The results with DriveApp are as expected, but Google Drive API v3 results in:</p>
  
  <pre><code>"files": [
  {
    "kind": "drive#file",
    "id": "01abc123_etc",
    "name": "Something something (2021-04-15).pdf",
    "mimeType": "application/pdf"
  },
  {
    "kind": "drive#file",
    "id": "02ABC4321-qwertyuiop",
    "name": "Super Special Worksheet",
    "mimeType": "application/vnd.google-apps.spreadsheet"
  },
  {
    "kind": "drive#file",
    "id": "whatever",
    "name": "Copy of V1",
    "mimeType": "application/vnd.google-apps.folder"
  },
  ...
  </code></pre>
  
  <p>Any ideas?</p>
  
  <h2>Edit:</h2>
  
  <p>Thank you! The problem seems to be 'corpus' and 'space'. I have used to following in Google AppsScript:</p>
  
  <pre><code>var options = {
    'contentType': 'application/json',
    'method'     : 'get',
    'headers'    : { Authorization: 'Bearer ' + service.getAccessToken() },
    'muteHttpExceptions': true,
    'pageSize'   : 100
  };
  url += '?q=' + encodeURIComponent(query);
  if ( pageToken.length &gt; 0 ) url += '&amp;pageToken=' + pageToken;
  var response = UrlFetchApp.fetch(url, options);
  </code></pre>