I’m working on a project that uses Google Forms with Zapier. I’ve set up a Google Apps script that makes a new folder in Google Drive when someone submits the form. Now I want to send the location of this new folder to Zapier so I can use it in my workflow.
Here’s what my script looks like right now:
function handleFormSubmission() {
try {
let mainForm = FormApp.getActiveForm();
let parentDir = DriveApp.getFolderById('MAIN_FOLDER_ID');
let latestResponse = mainForm.getResponses()[0];
let responseData = latestResponse.getItemResponses();
let submitterName = responseData[0].getResponse();
let existingFolders = parentDir.getFoldersByName(submitterName);
let userFolder = existingFolders.hasNext() ? existingFolders.next() : parentDir.createFolder(submitterName);
let timestamp = Utilities.formatDate(new Date(), 'PST', 'yyyy-MM-dd HH:mm:ss');
console.log(timestamp);
let timestampedFolder = userFolder.createFolder(timestamp + ' PST');
responseData[10].getResponse().forEach(fileId => DriveApp.getFileById(fileId).moveTo(timestampedFolder));
} catch(err) {
console.log(err);
}
}
Zapier already gets the usual form data. But how can I also send it the URL of the new Google Drive folder? Is there a way to do something like this:
I’ve tackled a similar challenge before, and here’s what worked for me. Instead of trying to return the folder URL directly, you can leverage Google Forms’ built-in email notification feature. Modify your script to send an email with the new folder URL, then set up a Zapier trigger to monitor that email address.
Here’s how you can adjust your script:
// At the end of your handleFormSubmission function
let folderUrl = timestampedFolder.getUrl();
let emailBody = 'New submission folder: ' + folderUrl;
GmailApp.sendEmail('[email protected]', 'New Form Submission', emailBody);
Then in Zapier, create a trigger for new emails to that address. This approach is more reliable than webhooks in my experience, as it doesn’t require maintaining a separate webhook URL. Plus, you get a backup of the folder links in your email if anything goes wrong with Zapier.
hey, u could try using the google forms onFormSubmit trigger. it lets u run ur script when the form is submitted. then u can grab the folder url and send it to zapier using UrlFetchApp.fetch() like this:
You can send the new folder’s URL to Zapier by adding a webhook request at the end of your script. Once you’ve created your folder, capture its URL using the getUrl() method from Google Drive. Then, use UrlFetchApp.fetch() to make a POST request to your Zapier webhook, including the folder URL in the JSON payload.
For example:
let folderUrl = timestampedFolder.getUrl();
let zapierWebhookUrl = 'YOUR_ZAPIER_WEBHOOK_URL_HERE';
let payload = { 'new_folder_link': folderUrl };
UrlFetchApp.fetch(zapierWebhookUrl, {
method: 'post',
contentType: 'application/json',
payload: JSON.stringify(payload)
});
Replace ‘YOUR_ZAPIER_WEBHOOK_URL_HERE’ with your actual Zapier webhook URL. This method ensures Zapier receives the folder URL for further processing in your workflow.