question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

sharedWithMe field in files.list method returns Bad Request error 400 when sharedWithMe = false

See original GitHub issue
//get all of the files within a given parent (folder) and mimeType
const getFiles = (auth, parent, mimeType) => { 
    return new Promise((resolve, reject) => {
        let request = { //make the request header
            auth: auth,
            corpora: "user",
            spaces: "drive",
            includeTeamDriveItems: false,
            q: "sharedWithMe = false"
        }
        if (parent) { 
        //backticks for template literals https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals
            request.q += ` and '${parent}' in parents` //get all the user's files with the given mimeType
        } 
        if (mimeType) {
            request.q += ` and mimeType = '${mimeType}'` //get all the user's files with the given parent
        }
        drive.files.list(request, (error, response) => { //call the api files.list method https://developers.google.com/drive/v3/reference/files/list
            if (error) {
                reject(error)
            } else {
                let files = {}
                response.data.files.forEach(file => {
                    files[file.name] = file.id
                })
                resolve(files) //return an object with the name and id of the files
            }
        })
    })
}

When calling the function getFiles like so (where auth is my OAuth2Client):

getFiles(auth).then((files) => {
    console.log(files)
})

drives.files.list returns a Bad Request 400 error.

Changing request.q to “sharedWithMe = true” or even “sharedWithMe != false” returns the expected output.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
iTiamocommented, Apr 29, 2018

Thank you Justin for filing that bug and much appreciated for the tip. 😄

1reaction
JustinBeckwithcommented, Apr 29, 2018

Apologies for the trouble! This looks like a bug with the underlying API. I can reproduce this pretty easily here: https://developers.google.com/drive/v3/reference/files/list

Sadly, that means there isn’t much I can do with it. I filed an internal bug in hopes of getting the issue cleared up, and I’ll report back here if there are any changes there.

On a side note - you don’t have to do all that song and dance for promises! We added native promise support in 28.1.0, so you can just do this:

//get all of the files within a given parent (folder) and mimeType
const getFiles = (auth, parent, mimeType) => { 
  let request = { //make the request header
    auth: auth,
    corpora: "user",
    spaces: "drive",
    includeTeamDriveItems: false,
    q: "sharedWithMe = false"
  }
  if (parent) { 
    request.q += ` and '${parent}' in parents` //get all the user's files with the given mimeType
  } 
  if (mimeType) {
    request.q += ` and mimeType = '${mimeType}'` //get all the user's files with the given parent
  }
  
  return drive.files.list(request).then(r => {
    let files = {};
    r.data.files.forEach(f => files[f.name] = f.id);
    return files;
  });
}

Hope that helps 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Fix a 400 Bad Request Error (Causes and Fixes) - Kinsta
The 400 Bad Request error indicates that the server cannot or process the request due to a client error. Read about the common...
Read more >
query 'sharedWithMe=false' Invalid Value? - Stack Overflow
This is a bug. It seems that the documentation doesn't reflect the actual behavior for the sharedWithMe Search Query Term.
Read more >
Solved: Move File - Bad Request - Power Platform Community
I always get a "Bad Request" with a status code of 400 when using the "Move File". The error details: Failed to verify...
Read more >
Version News for Windows - GoodSync
Update news for GoodSync's Windows file sync and backup software. ... Fixed returning Error 518 'Direct Server is still computing response' in wrong...
Read more >
NetSuite Applications Suite - Editing a Dataset
Item Search Displays Incorrect Results · Category Product Lists Return Page Not ... select Shared with me in the dropdown list of either...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found