Retrieving subfolder list from Google Drive using parent folder ID

Hey everyone, I’m having trouble with the Google Drive API. I’m trying to fetch all the subfolders within a specific folder using its parent folder ID. I’ve been using the v3 API endpoint, and I can successfully create new files and folders under the parent folder. However, when I attempt to get a list of folders inside the parent, I keep getting a ‘bad request’ error. Here’s what I’ve tried:

  • Endpoint: content.googleapis.com/drive/v3/files/
  • Method: GET
  • Passing the parent ID in the request body
    I’m testing this using Postman. Has anyone encountered this issue before? Any ideas on what I might be doing wrong or if there’s a better way to approach this? Thanks in advance for any help!

Hey Oscar64, I’ve been in your shoes before with the Google Drive API. One thing that helped me was using the ‘fields’ parameter in my GET request. Try adding ‘?fields=files(id,name,mimeType)’ to your endpoint. This tells the API exactly what data you want back, which can sometimes resolve ‘bad request’ errors.

Also, make sure you’re using the correct authentication method. I once spent hours debugging only to realize I was using an API key instead of OAuth 2.0. For folder operations, you definitely need OAuth.

Lastly, if you’re still stuck, try enabling the Drive API in your Google Cloud Console. Sometimes it’s not activated by default, which can cause cryptic errors. Good luck, and let us know if you make progress!

hey Oscar64, i’ve dealt with this before. sounds like you’re close! try adding a query parameter to your GET request instead of using the body. something like: ?q=‘parentId’ in parents

Also make sure you’re including the right scopes in your auth token. Good luck!

I’ve worked extensively with the Google Drive API, and I can offer some insights. The issue you’re encountering is likely due to how you’re structuring your request. For retrieving subfolder lists, you should use the ‘files.list’ method instead of ‘files.get’. The correct endpoint would be:

https://www.googleapis.com/drive/v3/files

Include query parameters to filter results:
?q=‘[PARENT_FOLDER_ID]’ in parents and mimeType=‘application/vnd.google-apps.folder’

This will return only folders within the specified parent. Also, ensure your authorization header is correctly set with a valid access token. If you’re still encountering issues, double-check your API credentials and make sure you have the necessary permissions for the folder you’re trying to access.