Update Products Immediately From Google Sheets Script

We have some existing templates that allow you to pull data from Google Sheets whenever a row is created that work off of a schedule.

But if you need to pull data in when it’s updated in Google Sheets immediately, this is a great option. It works by setting up an Apps Script under the Extensions > Apps Script menu that will send a webhook to MESA every time a row is updated:

Watch The Demo

The Apps Script Code You Will Paste In

function onEdit(e) {
  var sheet = e.source.getActiveSheet();
  var range = e.range;
  var editedRow = range.getRow();
  var headersRange = sheet.getRange(1, 1, 1, sheet.getLastColumn());
  var headers = headersRange.getValues()[0];
  var valuesInEditedRow = sheet.getRange(editedRow, 1, 1, sheet.getLastColumn()).getValues()[0];
  
  // Create an object to store the key-value pairs
  var rowData = {};

  // Iterate through the headers and values to create the object
  for (var i = 0; i < headers.length; i++) {
    var header = headers[i];
    var value = valuesInEditedRow[i];
    rowData[header] = value;
  }

  postWebhook(rowData);

}

function postWebhook(payload) {
  let jsonPayload = JSON.stringify(payload);
  let webhookUrl = 'INSERT WEBHOOK URL HERE';

  // Send the JSON payload to the webhook URL using a POST request
  var options = {
    method: "post",
    contentType: "application/json",
    headers: { 'Accept': '*/*' },
    muteHttpExceptions: true,
    accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*; q = 0.8',

    // muteHttpExceptions: true,
    payload: jsonPayload
  };

  Logger.log("Payload: " + jsonPayload);

  var response = UrlFetchApp.fetch(webhookUrl, options);
  Logger.log(response.getContentText());
}

Preview Workflow

How do I use this demo file?

  1. Add MESA from the Shopify App Store. Enjoy a 7-day free trial to start.
  2. Import this download to My Workflows. Navigate to your automations then follow the prompt to import a workflow. Upload the downloaded ZIP file from this demo.
  3. That's it! Personalize any step if you want. You got this.
  4. Questions? Shoot me an email: kalen.jordan@getmesa.com
We literally wrote the book on Shopify automation

Learn how to make Shopify work easier with your business processes.

Get the playbook - Free!

shopify automation playbook PDF