Input

Input task is triggered manually by the user. Before it runs, it will ask you to upload a file. The uploaded file is then available in the code editor via the preloaded file object.

The file object

The code editor has a file object preloaded. Unlike other preloaded objects, file is not a parsed array of rows. Instead, it is an object with the following properties:

Property
Type
Description

file.name

string

The original filename including extension (e.g. "products.csv", "feed.xml")

file.content

string

The raw text content of the uploaded file

file.size

number

The file size in bytes

Because file.content is a raw string, you need to parse it yourself using the appropriate filter for your file format.

Parsing file content

Use the filename to detect the format and parse accordingly:

{% assign content_parsed = "" %}

{% if file.name contains ".csv" %}
  {% assign content_parsed = file.content | parse_csv %}
{% elsif file.name contains ".xml" %}
  {% assign content_parsed = file.content | parse_xml %}
{% else %}
  {% log file.content %}
{% endif %}

{% if content_parsed %}
  {% for row in content_parsed %}
    {% log row %}
  {% endfor %}
{% endif %}

CSV files

The parse_csv filter parses a CSV string into an array of objects. The first row is used as headers — each subsequent row becomes an object with header names as keys.

XML files

The parse_xml filter parses an XML string into a Liquid object. Elements become object keys, text content becomes values, and repeated elements become arrays.

JSON files

For JSON files, use the parse_json filter:

Plain text and other formats

If the file is not CSV, XML, or JSON, you can work with file.content directly as a string. Use Liquid string filters like split, strip, etc.

Example: GraphQL mutation with CSV import

This example reads a CSV file with an email column and creates a Shopify customer for each row:

Lines 1-13 capture a GraphQL mutation for creating a customer. Lines 15-21 define the variables required for the mutation. The CSV file is then parsed using parse_csv, and the for loop iterates through each row, assigning the row's email to variables.input.email. With mutation input prepared, the GraphQL query executes and creates the customer.

Example: XML product feed import

Last updated