Search text content of files by keyword using the Google Drive API

Example of getting the contents of a Google Doc via the Google Drive REST API in javascript.

Find files by searching their contents using vanilla javascript

const phrase = "search for this phrase"
let fetch_url = `https://www.googleapis.com/drive/v3/files?orderBy=folder&q=trashed%3Dfalse%20and%20fullText%20contains%20%27${encodeURIComponent(
phrase
)}%27`;
let fetch_options = {
method: "GET",
headers: {
    Authorization: `Bearer ${token}`,
    "Content-Type": "application/json",
},
};

const response = await fetch(fetch_url, fetch_options);
const json = await response.json();

For other Google Drive API Examples: https://www.mikesallese.me/tags/google-drive-api-examples

Still need help?

Didn't find what you need? I'm happy to help folks out.

Feel free to email me at