2
votes

Question on listing the folders under shared drive.

I was able to get successful response while calling the API below by passing query parameters as:

  • includeTeamDriveItems=true
  • q=‘0AATe_aghhsdfvbdfg’ in parents and mimeType = ‘application/vnd.google-apps.folder’
  • supportsAllDrives=true

API: https://developers.google.com/drive/api/v3/reference/files/list?apix_params=%7B%22includeTeamDriveItems%22%3Atrue%2C%22q%22%3A%22%270AATe_aghhsdfvbdfg%27%20in%20parents%20and%20mimeType%20%3D%20%27application%2Fvnd.google-apps.folder%27%22%2C%22supportsAllDrives%22%3Atrue%7D

Successful Response:

{
 "kind": "drive#fileList",
 "incompleteSearch": false,
 "files": [
 {
  "kind": "drive#file",
  "id": "1E-c0rNCQMlQvXNUGTKSWdPHBOwwzjtcf",
  "name": "Integration",
  "mimeType": "application/vnd.google-apps.folder",
  "teamDriveId": "0AATe_aghhsdfvbdfg",
  "driveId": "0AATe_aghhsdfvbdfg"
 },
 {
  "kind": "drive#file",
  "id": "1QOMRSPuE1msJJmyr3yJOMZsBrn3nrtAx",
  "name": "Folder1",
  "mimeType": "application/vnd.google-apps.folder",
  "teamDriveId": "0AATe_aghhsdfvbdfg",
  "driveId": "0AATe_aghhsdfvbdfg"
 }
 ]
}

Question: From the response, it returns existing folders under the shared drive. Is it possible to also get all the sub folders under parent folders at once instead of having to pass parent folder ID under query parameters each time ? (e.g: To get all the sub folders under parent folder ‘Integration’)

  • Dilip
1
The folders just under the parent folder can be retrieved by the search query with one API call. But, all nested subfolders under the parent folder cannot be directly retrieved. In this case, it is required to prepare a script. Unfortunately, in the current stage, it seems that this is the current specification. I apologize for this.Tanaike
Hi @Tanaike ! Your comment is correct, could you please formalise it into an answer so that it is easier to find for those with similar questions? Thanks !Mateo Randwolf
@Mateo Randwolf Thank you for your support. Yes. I posted it as an answer.Tanaike

1 Answers

1
votes
  • The folders just under the parent folder can be retrieved by the search query with one API call like below. In this case, 'folderId' in parents is used as the search query.

      curl \
        'https://www.googleapis.com/drive/v3/files?corpora=drive&driveId=driveId&includeItemsFromAllDrives=true&q=%27folderId%27%20in%20parents&supportsAllDrives=true' \
        --header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
        --header 'Accept: application/json' \
        --compressed
    
    • And, when you want to retrieve the files under 2 folders, you can also use the following sample. In this case, 'folderIdA' in parents or 'folderIdB' in parents is used as the search query.

        curl \
          'https://www.googleapis.com/drive/v3/files?corpora=drive&driveId=driveId&includeItemsFromAllDrives=true&q=%27folderIdA%27%20in%20parents%20or%20%27folderIdB%27%20in%20parents&supportsAllDrives=true' \
          --header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
          --header 'Accept: application/json' \
          --compressed
      
    • From your question, I think that you have already been done above.

  • In the current stage, all nested subfolders under the parent folder cannot be directly retrieved.

    • In this case, it is required to prepare a script.

    • Unfortunately, in the current stage, it seems that this is the current specification at Google side.

Note:

  • In the most cases, includeItemsFromAllDrives=true and supportsAllDrives=true can be used. But I had the some cases that corpora=drive and driveId=### are also required. So when in your shared Drive, the files cannot be retrieved, please try to use this.

References: