DataJet
  • Welcome to DataJet
  • Scripts
    • Introduction
    • Scripts
      • Input
      • HTTP
      • Scheduled
      • Event
      • Shipping Rate
      • Email
    • Creating a custom script
  • Liquid
    • Introduction
    • Tags
      • exit
      • function
      • json
      • push
      • run
    • Filters
      • array_difference
      • array_equal
      • array_intersection
      • array_symmetric_difference
      • base64_decode
      • base64_encode
      • concat
      • content
      • email
      • encode_uri
      • file
        • multipart
        • url
        • content
      • find
      • find_exp
      • flat
      • flow
      • flow_v2
      • ftp
      • graphql
      • group_by
      • group_by_exp
      • hmac_sha256
      • http
      • in_groups_of
      • in_timezone
      • log
      • parse_json
      • parse_csv
      • parse_xml
      • pop
      • push
      • random
      • remove_prop
      • rest
      • run
      • sha1
      • sum
      • time_add
      • time_subtract
      • type
      • where_exp
  • Misc
    • Credits and usage
    • GitHub Integration
      • Track changes in a script's source code
      • Connect development stores with development branches
      • Use one codebase across multiple Shopify stores
    • Functions
    • Variables
    • Shopify Flow Integration
      • V1
      • V2
    • Processing user submitted forms
Powered by GitBook
On this page
  1. Scripts
  2. Scripts

Input

Input task is triggered manually by the user. Before it runs, it will ask you to upload a file. Later this file is available in code editor. This means you can easily access rows of your file and perform certain operations.

Looping over file rows is simple:

{% for row in file  %}
    {{ row["Your Column Name"] | log }}
{% endof %}

Above snippet is going log each row value for column named Your Column Name .

Code editor is going to have file object preloaded. This object is an array with JSON objects. Each JSON object has properties named exactly as columns in your source file.

{% capture mutation %}
    mutation customerCreate($input: CustomerInput!) {
      customerCreate(input: $input) {
        customer {
          id
        }
        userErrors {
          field
          message
        }
      }
    }
{% endcapture %}

{% json variables %}
    {
      "input": {
        "email": ""
      }
    }
{% endjson %}

{% for row in file %}
  {% assign variables.input.email = row['email'] %}
  {% assign result = mutation | graphql: variables %}

  {% if result.customerCreate.userErrors != empty %}
    {{ result.customerCreate.userErrors[0] | log }}
  {% else %}
    {{ "Created new customer with id: " | append: result.customerCreate.customer.id | log }}
  {% endif %}

{% endfor %}

Next, in lines 1-13 we capture GraphQL mutation for creating a customer. Lines 15-21 define variables required for GraphQL mutation. Next we use for loop to go through the file rows and for each row assign email to variables.input.email.

Having mutation input ready we execute GraphQL query and create our customer.

PreviousScriptsNextHTTP

Last updated 2 years ago