DataJet
Search…
Creating a custom task
With DataJet you are not limited to OOTB tasks only. Built in code editors give you a chance to built any integration you require. Possibilities are endless - your limit is your imagination. There are couple of things to keep in mind when creating a task. 1. Permissions
To keep security at highest level app would requests only very basic permissions when installed. However, when creating a task some additional permissions might be required, for example you might need write_orders permission to add a tag to an order. App automatically detects required permissions when task code is compiled. However you need to help compiler a bit. When defining REST/GraphQL requests do it at very top of the task:
1
{%- comment -%}Start REST and GraphQL definitions{%- endcomment -%}
2
{% capture mutation %}
3
mutation tagsAdd($id: ID!, $tags: [String!]!) {
4
tagsAdd(id: $id, tags: $tags) {
5
node {
6
id
7
}
8
userErrors {
9
field
10
message
11
}
12
}
13
}
14
{% endcapture %}
15
Copied!
Next, you can use dummy input to tell compiler what variables it should expect.
1
{%- comment -%} Feed compiler with dummy values to evaluate permissions required.{%- endcomment -%}
2
{% if mode.compiler %}
3
{% json dummy_mutation_variables %}
4
{
5
"id": "gid://shopify/Order/123456",
6
"tags": "test"
7
}
8
{% endjson %}
9
{% assign result = mutation | graphql: dummy_mutation_variables %}
10
{% endif %}
11
{%- comment -%}END REST and GraphQL definitions{%- endcomment -%}
Copied!
Above code snippet won't be executed when your task actually runs. It is because it is wrapped in if condition. mode.compiler is set to true only when creating/editing task.
After adding above code, compiler knows what to expect from your task and can easily evaluate permissions it needs to run your task. You can now save it and return to app dashboard, you are going to be prompted to update app permissions.
After clicking Update permissions button you should see a popup window where you can update app permissions. Some browsers (e.g. Safari) blocks popups by default. You can allow your browser to display popups by clicking Unblock button next to URL field.
Here is how you would tell compiler about any REST request:
1
{%- comment -%}Start REST and GraphQL definitions{%- endcomment -%}
2
{% json fulfillment_request_options %}
3
{
4
"path": "",
5
"method": "POST",
6
"body": {
7
"fulfillment": {
8
"location_id": "123456",
9
"notify_customer": false,
10
"status": "success"
11
}
12
}
13
}
14
{% endjson %}
15
16
{%- comment -%} Feed compiler with dummy values to evaluate permissions required.{%- endcomment -%}
17
{% if mode.compiler %}
18
{% assign order_fulfillment_endpoint = "/orders/123456/fulfillments.json" %}
19
{% assign fulfillment_request_options["path"] = order_fulfillment_endpoint %}
20
{% assign result = fulfillment_request_options | rest %}
21
{% endif %}
22
{%- comment -%}END REST and GraphQL definitions{%- endcomment -%}
Copied!
Last modified 6mo ago
Copy link