FTP

The FTP (File Transfer Protocol) by MESA app allows you to download and upload files to a specified FTP server. With MESA, you can map the data to a format that Shopify or another system expects and pass it along to the next step. Sharing CSV and other files via FTP servers is a great choice to connect your fulfillment service, product manager, or another third-party system to Shopify. MESA supports both FTP and SFTP (secure FTP) protocols.

Connect FTP with MESA

Your hosting service should have details for all fields required to connect your FTP with MESA.

Once all the details have been filled in, click Add Credential to connect your FTP with MESA.

Configuration

Fetch File triggers

You can begin a workflow by fetching a FTP, XML, or CSV file on a scheduled basis.

Once you have selected your preferred FTP trigger, there are a variety of fields that you can complete:

File Name

Enter the path to the file on your FTP server.

To check that if you have correctly entered your path, you can click on the Check for CSV button to test.

If MESA cannot locate your file, an error will display, stating that the file is not found or could not be read. To fix this, please adjust the text entered into the File Name field.

Optional: You can use wildcards (*) to match portions of the path if the path is dynamic. If you are familiar with regular expressions, you can test the wildcard placement on a third-party website (e.g. regex101) to ensure that the pattern matches the file path.

First Row of CSV is Header

If selected, MESA will expect the file to contain column titles (headers) in the first row. This only displays in the FTP by MESA Fetch CSV File trigger.

Here is an example of a CSV file's headers.

Move File After Successful Read

If selected, the file will be moved after MESA successfully reads it. This is useful if you have a dedicated directory/folder to store read files so your FTP server is organized.

In the below screenshot, the processed folder stores all files that have been read.

For the Moved File Name field, you can use the Variable {{file}} which is from the file name. For example, if the file name value is orders/Order*.csv, and the found file was orders/Order-1234.csv, {{file}} would resolve to Order-1234.csv.

For our example, we have inputted: processed/orders/{{file}}

Scheduled Time

At the very bottom of the configuration, you can configure how often you'd like your workflow to run. Make sure to click Save to save your changes!

CSV Advanced Options: Delimiter Character

This field lets you input a single character that determines how the rows in a file are split. This field defaults to ',' and should be correct in most cases.

XML Advanced Options: Namespace Seperator

This field lets you input a namespace seperator that replaces soapenv:Body type values with soapenv_Body. If the XML file being read does not contain namespaces, this field is optional.


Save FTP File action

In the File Name field, you can input your preferred name of the file that will be sent to your FTP server.

Example: products/all-products-{{date:_m_d_Y_h_i_s_A}}.csv will create a file in the products folder, with the name all-products-_07_30_2023_09_48_54_AM.csv

You can take a look at how to use Date Advanced Variables here.

In the Data Mapping section, you can map out the data sent to your FTP server by utilizing MESA's Variables feature.

Advanced Data Mapping

For more advanced mapping, you can also use the Edit Code button on the FTP action, then add in your own data mapping.

The following code will take a list of Shopify products, and create CSV file content from them. The Mesa.csv.encode() method is used to convert the data into CSV format. See the MESA Script SDK documentation for more details.

script = (payload, context) => {
  // Adjust `payload` here to alter data before we transform it.

  // Alter the payload data based on our transform rules
  let csvRows = [];

  payload.forEach(product => {
    csvRows.push({
      id: product.id, 
      title: product.title, 
      handle: product.handle, 
      status: product.status
    });
  });

  // Adjust `output` here to alter data after we transform it.
  const csvOutput = Mesa.csv.encode(csvRows, true);

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

Last updated