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

Below is a detailed guide outlining the steps to automate the merging of all files within a Google Drive folder.

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

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

Step 3: Test Trigger

Now, let's test the trigger to create a record for scheduling our Zap to activate.

Test trigger

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

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

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

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

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

Step 9: Send HTTP Request

Now, let's test the action to send the HTTP request to Google Drive.

Send HTTP Request

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

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

Step 12: Send Loop to Zapier

Let's test the Looping by Zapier to iterate through each File IDs.

Send Loop to Zapier

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

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

Step 15: Send Share File

Now, let's share the file on Google Drive to make it accessible to the public.

Send share file

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

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

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

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

Step 20: Send Run Python

Now, let's run the Python code to get the formatted URLs.

Run Python code

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

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

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

Step 24: Merge PDF Result

Here’s the merged PDF file from Google Drive folder.

Merge PDF Result

The workflow so far will look like this:

Complete workflow

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

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

Step 27: Test File Upload

Test the file upload by sending a request to Google Drive.

Upload File in Google Drive

Step 28: Open Google Drive Folder

After a successful upload, open the Google Drive folder to view the uploaded file.

Invoice Final Result

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!