Merge All Files in Google Drive Folder Using Zapier
In this tutorial, we will guide you through the steps to merge all files that are stored within a designated Google Drive folder. You can easily combine multiple files into a single document by using PDF.co along with Zapier for automation.
![Merge multiple files in Google Drive](/_next/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2F2niroq9z%2Fproduction%2Fb03c31c7d8230c9fab340d1386eb21ab2cec1117-780x435.png&w=1920&q=75)
Below is a detailed guide outlining the steps to automate the merging of all files within a Google Drive folder.
Contents
Step 1: Schedule by Zapier
To begin, let's set up our Zap to initiate the file merge at the start of the day using Schedule by Zapier.
![Schedule by Zapier](/_next/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2F2niroq9z%2Fproduction%2Fbcab874444f9f4463757fb731c1cb709012597d8-780x415.png&w=1920&q=75)
Step 2: Setup Trigger
- Enter the desired time of day in the "Time of Day" field to specify when you want this action to trigger.
- You can choose to enable or disable the option to trigger the Zap on weekends by selecting "Yes" or "No" accordingly.
![Every day schedule](/_next/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2F2niroq9z%2Fproduction%2F14280822136f43ca7574dd21b7626b502d58ec5d-780x500.png&w=1920&q=75)
Step 3: Test Trigger
Now, let's test the trigger to create a record for scheduling our Zap to activate.
![Test trigger](/_next/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2F2niroq9z%2Fproduction%2F9570fe4de3b50ac09fa776e6c867a47d8356b47d-780x815.png&w=1920&q=75)
Step 4: Google Drive Find a Folder
Next, we will add the Google Drive module to find the folder where our files are stored. It's important to note that the Google Drive folder needs to be publicly accessible during the PDF Merge. This can be manually set in your Google Drive settings.
![Find a folder](/_next/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2F2niroq9z%2Fproduction%2Fc862f0514ce3e392547c51eaa7f6273c3cd00955-780x390.png&w=1920&q=75)
Step 5: Setup Find Folder in Google Drive
Enter the folder name in the "Folder Name" field where the files are stored, and choose "My Google Drive" as the drive to be used.
![Find a folder](/_next/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2F2niroq9z%2Fproduction%2Fcf5229ed57cdf69b317010521ec51453a6c92b81-780x725.png&w=1920&q=75)
Step 6: Test Find Folder
Now, let's test the find folder step to retrieve the folder from Google Drive where the files are stored.
![Test find a folder](/_next/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2F2niroq9z%2Fproduction%2F0960b1fd989dc9ad8e88cc4964225f0c4556883d-780x890.png&w=1920&q=75)
Step 7: Google Drive API Request
Then, we will use the Google Drive API Request to get all the files stored in the folder.
![API Request](/_next/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2F2niroq9z%2Fproduction%2F6d0cf65003a0233485b3e0bda7a9b9f3273aa737-780x410.png&w=1920&q=75)
Step 8: API Request Setup
- Select "GET" as the "HTTP Method".
- In the "URL" field, enter the service endpoint "https://www.googleapis.com/drive/v3/files".
- Within the Query String Parameters, input the letter "q" to search for a particular set of files or folders, and include the value as
'{{unique folder id}}' in parents
to indicate the folders where the files are located.
![API Request configuration](/_next/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2F2niroq9z%2Fproduction%2Fbf3298efe9525b5bc459c0c8f0e9881b43eddfed-780x730.png&w=1920&q=75)
Step 9: Send HTTP Request
Now, let's test the action to send the HTTP request to Google Drive.
![Send HTTP Request](/_next/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2F2niroq9z%2Fproduction%2Fb7b61762ac24fad95fb1961104bb209fed5bd274-780x915.png&w=1920&q=75)
Step 10: Looping by Zapier
We will add the Zapier's looping feature into our workflow to handle each File ID separately. We will utilize the Create Loop From Line Items option.
![Create loop](/_next/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2F2niroq9z%2Fproduction%2Fd2da2cb2a329840dbbdbc0fe4db089ba8b944fa2-780x445.png&w=1920&q=75)
Step 11: Create Loop from Line Items
Enter the variable name for the File IDs in the Values to Loop field. This variable will point to each File ID in the loop. In the following text box, choose the value Response Data File IDs from the Google Drive module.
![Configure Create Loop](/_next/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2F2niroq9z%2Fproduction%2F50778809277234cb61d8d9dc55020bf4adde59d0-780x530.png&w=1920&q=75)
Step 12: Send Loop to Zapier
Let's test the Looping by Zapier to iterate through each File IDs.
![Send Loop to Zapier](/_next/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2F2niroq9z%2Fproduction%2F5f9537836a59627cb8a06eedbf46f89b3819f047-780x885.png&w=1920&q=75)
Step 13: Google Drive File Sharing
Now, we will enable the Google Drive file sharing option to provide access to the files stored in the folder.
![Google Drive File Sharing](/_next/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2F2niroq9z%2Fproduction%2F01b31439974cd0238bf0672ed7eb3203ab3afed3-780x435.png&w=1920&q=75)
Step 14: Setup File Sharing Preference
- Choose "My Google Drive" in the Drive field.
- Select the File IDs from the loop for the File ID field.
- For the Sharing Preference field, select for the "Anyone on the internet has the link can view" option.
![File Sharing Preference](/_next/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2F2niroq9z%2Fproduction%2F115dce3d36a0f6aa0ebcbbadcc7d05a0193a497e-780x585.png&w=1920&q=75)
Step 15: Send Share File
Now, let's share the file on Google Drive to make it accessible to the public.
![Send share file](/_next/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2F2niroq9z%2Fproduction%2F18c4ca9c5defdab238d47693fe54b41386ac7521-780x835.png&w=1920&q=75)
Step 16: Filter by Zapier
Then, let’s add the Filter by Zapier to allow us to set rules that determine when a particular action should or should not be taken in a zap.
![Filter by Zapier](/_next/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2F2niroq9z%2Fproduction%2Fb0f8687cea46d27bb7d807a9df6c47c21f21c8a6-780x355.png&w=1920&q=75)
Step 17: Add Condition
We will set the condition to proceed if the Loop Iteration is Last is False and the value of Boolean is true.
![Add Condition](/_next/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2F2niroq9z%2Fproduction%2F750284ccc377f1aa076414446cdf16bc25669a2c-780x700.png&w=1920&q=75)
Step 18: Code by Zapier
The PDF Merge accepts URLs separated by commas. Let's use the Code by Zapier to format the Google Drive links correctly for PDF Merge.
![Run Python in Code by Zapier](/_next/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2F2niroq9z%2Fproduction%2Ff23cb8370e4b6e22cf62e0f3f3bd3ea1250611df-780x430.png&w=1920&q=75)
Step 19: Initiate Python Code
- In the “Input Data” field, include the key names and link the file's values with the “Response Body” from API Request Google Drive.
- Next, enter the Python code below in the "Code" field.
import json
# Initialize an empty string for the new URL
new_url = ""
# Get the folder data from the input data
folder_data_json = input_data["folder_ids"]
# Parse the JSON string to a Python dictionary
folder_data = json.loads(folder_data_json)
# Loop through each file in the folder data
for item in folder_data["files"]:
folder_id = item['id']
mime_type = item['mimeType']
if mime_type == "application/vnd.google-apps.spreadsheet":
# For Google Sheets, use the export to PDF link
new_url += "https://docs.google.com/spreadsheets/d/" + folder_id + "/export?format=pdf" + ","
elif mime_type == "application/vnd.google-apps.presentation":
# For Google Slides, use the export to PDF link
new_url += "https://docs.google.com/presentation/d/" + folder_id + "/export?format=pdf" + ","
else:
# For PDF, PNG, JPEG, TIFF, and any other files, use the direct download link
new_url += "https://drive.google.com/uc?id=" + folder_id + ","
# Remove the trailing comma from the new URL
new_url = new_url.rstrip(",")
# Create an output dictionary with the formatted URL
output = {"formatted_url": new_url}
![Initiate python code](/_next/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2F2niroq9z%2Fproduction%2Ff0f6a2e8c0676f729ab0771bb3f178f8fbb30852-780x755.png&w=1920&q=75)
Step 20: Send Run Python
Now, let's run the Python code to get the formatted URLs.
![Run Python code](/_next/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2F2niroq9z%2Fproduction%2F75a1fcb40a2f91bf93afde29fb8430e91cb5fc3d-780x730.png&w=1920&q=75)
Step 21: PDF.co PDF Merger
Let's add the PDF.co PDF Merger module to merge all the files in the Google Drive folder into a single PDF file.
![PDF Merger in PDF.co](/_next/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2F2niroq9z%2Fproduction%2F19e5c291a3d4e488cd9c6ac9d4ff4ac34a3d74ca-780x410.png&w=1920&q=75)
Step 22: Setup PDF Merger
- Enter the formatted URL generated by the Code by Zapier module in the "Source File URLs" field.
- Set the "Automatically Convert Non-PDF Files" field to “false” if you are merging only PDF files, and set it to “true” if you are merging a combination of PDF and non-PDF files.
![Merge_PDF](/_next/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2F2niroq9z%2Fproduction%2F24ef46da11ae836a12e3e0051a4ccdca1a5edd40-780x650.png&w=1920&q=75)
Step 23: Test PDF Merger
Let's now test the PDF Merger. Once successful, copy the URL and paste it into your browser to see the result.
![Result URL](/_next/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2F2niroq9z%2Fproduction%2F23ad89ae387efd0a914a9323c86c4864e9242873-780x870.png&w=1920&q=75)
Step 24: Merge PDF Result
Here’s the merged PDF file from Google Drive folder.
![Merge PDF Result](/_next/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2F2niroq9z%2Fproduction%2F00d42289c27a71e301da3f79bed27cc01f3a614c-780x455.png&w=1920&q=75)
The workflow so far will look like this:
![Complete workflow](/_next/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2F2niroq9z%2Fproduction%2F7e36228cf461d7357fdf5f1a35fd8a082e050b30-1004x1330.png&w=2048&q=75)
Finally, let's add another module to send the PDF output. In this tutorial, we will upload the PDF to another Google Drive folder.
Step 25: Google Drive Upload File
Let's upload the merged PDF file to Google Drive folder.
![Upload a file](/_next/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2F2niroq9z%2Fproduction%2F25abc67ee076a6aac6980be23f038241c3bf12a4-780x400.png&w=1920&q=75)
Step 26: Configure Upload File
- Choose "My Google Drive" as the designated drive.
- Specify the folder name where you wish to save the merged PDF.
- Input the generated file URL of the merged PDF to store in the Google Drive folder.
![Configure Upload File](/_next/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2F2niroq9z%2Fproduction%2Fc99bbbbb4817e6361cccfee95f0098b04886f1e8-780x625.png&w=1920&q=75)
Step 27: Test File Upload
Test the file upload by sending a request to Google Drive.
![Upload File in Google Drive](/_next/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2F2niroq9z%2Fproduction%2Feb5a5cdc20f9e7a31d15b6fe43e9490b0fd465d3-780x885.png&w=1920&q=75)
Step 28: Open Google Drive Folder
After a successful upload, open the Google Drive folder to view the uploaded file.
![Invoice Final Result](/_next/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2F2niroq9z%2Fproduction%2F4122c911c64d130633fc57712a4ca64ceafa1b7d-780x545.png&w=1920&q=75)
In conclusion, merging multiple files from a Google Drive folder into a single document is straightforward with PDF.co and Zapier. This tutorial has shown you how to set up and automate the process, enhancing your workflow and saving time. With this efficient solution, document management becomes a breeze. Try it today and see the difference!