I want to pass q parameter in setEndPoint url to get list of all files in the root folder(at the home page). I tried it using the google API(https://developers.google.com/drive/api/v3/reference/files/list) it is working there,but when I try to use in for REST API it generates error.Following is my url

HttpRequest req = new HttpRequest();
        req.setMethod('GET');   // Http method of get is used here.
        // setEndPoint url parameters are passed 
        req.setEndpoint('https://www.googleapis.com/drive/v3/files?corpora=user,allTeamDrives&includeTeamDriveItems=true&supportsTeamDrives=true&q=\'root\'in parents');

This generates an error on my vf page. As soon as I remove q parameters the error is removed

1 Answer 1


It could be a number of reasons, but presumably it's because of a missing space or the fact that you didn't encode the parameters correctly. I would expect it to look more like:


You might want to take a look at EncodingUtil's urlEncode to make sure that you're properly escaping reserved characters.

'...q='+EncodingUtil.urlEncode('\'root\' in parents', 'utf-8')

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .