Update Products Immediately From Google Sheets Script

While our existing templates allow for scheduled data pulls from Google Sheets whenever a row is created, this workflow caters to immediate updates. By setting up an Apps Script under the Extensions > Apps Script menu, this workflow sends a webhook to MESA every time a row is updated. Perfect for real-time inventory management and product updates, this solution ensures your Shopify store always reflects the latest data from your Google Sheets.

Watch the demo

Example spreadsheets

The Apps Script code

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 steps

Free download

This free workflow template if yours to personalize. Simply import the ZIP file to MESA then connect the app steps to your credentials. Test, then, turn it on!

What you should do now

Whenever you’re ready…here are 4 ways we can help you grow your business:

  1. Add MESA to your Shopify store. The best way to get started is by adding the MESA app from the Shopify App store. Every plan includes the first 7-days free so you can be assured your workflow is running properly.
  2. Import this workflow. Download this .ZIP file then import it into your MESA workflows.
  3. Questions? Contact Kalen Jordan. MESA Service Partners can help personalize workflows or make any automations your business requires.
  4. If you know another merchant who’d enjoy reading this, share it with them via LinkedIn, YouTube, Twitter, or Facebook.

Automate anything and get more from your apps.
For free.

Start free trial

Automate everything with MESA

Make any workflow and get more from your existing apps.

Try MESA for free, 7-day trial included.