Writing Scripts

The most basic MESA Script exports a class with a script() method. The code is executed in a V8 environment and can be written in standard Javascript or ES6. The class can contain additional methods or variables.

Parameters

During runtime, the script() method will be called and passed two parameters, payload and context.

The context parameter contains (read full details):

NameTypeDescription

payload

object

The payload data

shop

Complete Shopify shop object

shop.email

string

Merchant's email address

shop.myshopify_domain

string

Shop string. Example: myshop.myshopify.com

shop.myshopify_domain

domain

Shop's domain if it has been customized, otherwise the myshopify domain

steps

object

An object containing the full payload for each step run in this automation so far, keyed by each step's key. For example steps.shopify.

trigger

The complete Trigger object contains information about the current step being run

task

The complete Task object contains information about this specific task run

automation

The complete Automation object contains information about the workflow

Basic MESA Script

const Mesa = require('vendor/Mesa.js');

/**
 * A MESA Script exports a class with a script() method.
 */
module.exports = new class {

  /**
   * MESA Script
   *
   * @param {object} payload The payload data
   * @param {object} context Additional context about this task
   */
  script = (payload, context) => {
    const vars = context.steps;

    // Add your custom code here
    // Line items from a Shopify Order Created trigger would be available as something like `vars.shopify.line_items`

    // We're done, call the next step!
    Mesa.output.next(payload);
  }
}

MESA Scripts can call any of the MESA SDK methods or methods from our libraries.

Timezones

All system timezones are in your Shopify Store's timezone. You can view and update your timezone from the Shopify Dashboard: Admin > Settings > General, under "Standards and formats". If you need to get dates in a different timezone, use the Mesa.date.setTimezone(timezone) method.

Unsupported nodejs methods

Scripts are run in a stock V8 environment. This means that some common NodeJS methods are not available:

Last updated