Email CSV file to user

I have a workflow to generate a csv of a table. I want the user to be able to receive the CSV as a file via email (not a link to the Glide stored file, but as an attachment to the email). I tried this through a web hook using google script t but it seems that glide won’t let the script access the url of the csv. Any ideas about how to achieve this?

That doesn’t sound right. The URL should be publicly accessible.

Personally, I would probably use Make. Send a webhook with the generated URL, use a HTTP module to download it, and a Gmail module to send the email.

1 Like

Well after living in the workflow and google script windows for an hour and watching it throw errors I went into my email and found that, in fact, it did work and it sent the file as expected so not sure why it was giving me a 302 error in workflows.

Hmmm. I’ll try your approach since this is not really working reliably.

This is also the way I have been doing it whenever I need an attachment. Wish Glide can let us do this right in the app.

I was really hoping to use google scripts. Doing some very basic testing and deploying the script as webhook/web app, when I run the script in glide it produces a 302 error every time. Is it not possible to use a google script as a web hook this way?

Can you show us how your script is set up?

This was the script for testing.


function doPost(e) {
  try {
    // Parse incoming data
    var data = {};
    if (e.postData && e.postData.contents) {
      data = JSON.parse(e.postData.contents);
    }

    // Log data to a Google Sheet
    logToSheet(data);

    // Build response
    var response = {
      success: true,
      message: "Data received",
      timestamp: new Date().toISOString(),
      receivedData: data
    };

    // Return response as JSON
    return ContentService
      .createTextOutput(JSON.stringify(response))
      .setMimeType(ContentService.MimeType.JSON);

  } catch (error) {
    var errorResponse = {
      success: false,
      message: error.toString(),
      timestamp: new Date().toISOString()
    };

    return ContentService
      .createTextOutput(JSON.stringify(errorResponse))
      .setMimeType(ContentService.MimeType.JSON);
  }
}

// Helper function to log to a sheet
function logToSheet(data) {
  const sheetId = 'YOUR_GOOGLE_SHEET_ID'; // <-- put your Sheet ID here
  const sheetName = 'Webhook Log'; // <-- or change if you want another sheet name
  
  const ss = SpreadsheetApp.openById(sheetId);
  const sheet = ss.getSheetByName(sheetName) || ss.insertSheet(sheetName);

  // Set up headers if the sheet is empty
  if (sheet.getLastRow() === 0) {
    sheet.appendRow(['Timestamp', 'Raw Data']);
  }

  // Append the new data
  sheet.appendRow([
    new Date().toISOString(),
    JSON.stringify(data)
  ]);
}

Please try this:

  1. Go to your Apps Script project editor.

  2. Click Deploy > Manage deployments .

  3. Find the active deployment you are using for the webhook.

  4. Click the Edit button (pencil icon).

  5. Change the settings to:

  • Execute as: Me (Your Google Account)

  • Who has access: Anyone, even anonymous

  1. Click Deploy . This will likely create a new version of the deployment. You may need to authorize the script yourself again when prompted during this process, granting your account permission to run it and access Sheets on your behalf.

  2. Important: Ensure you are using the Web app URL provided after this deployment in your Glide webhook action.

Thanks. This must be the solution because I’ve seen that advice elsewhere but wondered if Glide had some particular requirements I wasn’t aware of. Somehow I’m not doing this right but I’ll follow those steps again more carefully.

It seems like you have some sort of access problem. Glide might have been blocked by a consent screen while trying to execute it.

I agree. Is there anyway to log that so I can get a hint to what might be happening?

I would suggest trying the method above first to see if it helps. If it doesn’t help, some console.log() might help.

I’m truly flummoxed. Very carefully followed the approach suggested. I even tried it a second time from a personal google account in case there were some settings in my workspace google account (I could find none) that might be causing this. I tried the web app url in both the web hook and Call API workflows and same result: 302. Would love any further clues, but maybe I cut my losses and try it through Make

What if you open the URL in a new window in your browser. What happens?

I get an error: Script function not found: doGet

Does the URL you’re using end in /exec?

Yes, it does. https://script.google.com/macros/s/xxxx/exec

Seems like this might be the case.

1 Like

Argh. Ok. Well looking to Make next.