DataJet
Search…
Blank Input
Blank 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 hook editor. This means you can easily access rows of your file and perform certain operations.
Looping over file rows is really simple and looks like that:
1
{% for row in file %}
2
{{ row["Your Column Name"] | log }}
3
{% endof %}
Copied!
Above snippet will output to task logs each row value for column named Your Column Name .
Any hook placed in this task will have file object preloaded. This object is nothing else as an array with JSON objects. Each JSON object has properties named exactly as columns in your source file. Let's have a look how you can use this task to create customers in Shopify.
1
{% unless file %}
2
{% capture file %}
3
[{
4
"email": "[email protected]"
5
}]
6
{% endcapture %}
7
{% endunless %}
8
9
{% capture mutation %}
10
mutation tagsAdd($input: CustomerInput!) {
11
customerCreate(input: $input) {
12
customer {
13
id
14
}
15
userErrors {
16
field
17
message
18
}
19
}
20
}
21
{% endcapture %}
22
23
{% capture variables %}
24
{
25
"input": {
26
"email": ""
27
}
28
}
29
{% endcapture %}
30
31
{% assign variables = variables | parse %}
32
33
{% for row in file %}
34
{% assign variables.input.email = row['email'] %}
35
{% assign result = mutation | graphql: variables %}
36
37
{% if result.customerCreate.userErrors != empty %}
38
{{ result.customerCreate.userErrors[0] | log }}
39
{% else %}
40
{{ "Created new customer with id: " | append: result.customerCreate.customer.id | log }}
41
{% endif %}
42
43
{% endfor %}
Copied!
Lines 1-7 create dummy file object for validation purposes (when validating user code, no predefined objects are created). Next, in lines 9-21 we capture GraphQL mutation for creating a customer. Lines 23-29 capture variables required for GraphQL mutation. Next we use forloop 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 voila our customer is created.
Last modified 10mo ago
Copy link