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


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')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.