Using the expert editor for trigger conditions

For most use cases, you can setup trigger conditions using the visual editor. Under the hood, this creates conditions in a format called JSON. Using the expert editor, you can write these conditions by hand.

This guide is for users with knowledge of JSON. Some knowledge of Typescript may help to understand the format. You'll also need to use JSONPath expressions.

We recommend using the visual editor for most use cases.

Need Help?

If you are having trouble creating a workflow that does what you want, please contact us via the support bubble and we will help you.

Viewing conditions in the expert editor

You can switch between the expert editor and the visual editor using the link in the corner of the Conditions (optional panel.

A condition example

Let's use the example above, which is a new order is created trigger with the following conditions:

{

"all":[

{

"path":"$.subtotal_price_set.presentment_money.amount",

"operator":"greaterThan",

"value":100

},

{

"path":"$.currency",

"operator":"equal",

"value":"GBP"

}

]

}

Let's break this down a bit, starting with a look at the structure which a condition follows.

Condition structure

The structure of the Condition JSON object can be described using Typescript.

type ConditionProperties {

path: string;

operator: string;

value: any;

}


type NestedCondition = ConditionProperties | TopLevelCondition;

type AllConditions = { all: NestedCondition[] };

type AnyConditions = { any: NestedCondition[] };

type TopLevelCondition = AllConditions | AnyConditions;

At the top level, we have a TopLevelCondition , which is either a type of AnyConditions or AllConditions . These both describe a collection of NestedCondition s.

With AnyConditions , the conditions are evaluated using OR logic - i.e. the criteria matches if any of the conditions evaluate to true.

With AllConditions , the conditions are evaluated using AND logic - i.e. the criteria matches if all of the conditions evaluate to true.

The most common use of a NestedCondition is as a ConditionProperties type. This allows us to target a specific field in the event which triggered this workflow using a JSONPath expression, any compare it's value to another fixed value.

You can also nest other TopLevelCondition s using a NestedCondition , to make very sophisticated rules which use AND and OR logic in combination. This isn't presently supported by the visual editor, only by the expert editor.

Operators

The ConditionProperties type allows you to specify an operator which is used to compare the value of the field at the given path , with another fixed value . Depending on the type of the field at the given path , you can use different operators.

path field type Available operators
string

'equal'

'notEqual'

number

'equal'

'notEqual'

'greaterThan'

'greaterThanInclusive'

'lessThan'

'lessThanInclusive'

array

'contains'

'notContains'

boolean

'equal'

'notEqual'

Understanding the example

Let's look at our example, with the understanding of the structure.

{

"all": [

...

]

}

We can see that this TopLevelCondition uses all , so it is a AllConditions type. This means that all the conditions within [...] will be evaulated using AND logic.

Our first condition is:

{

"path":"$.subtotal_price_set.presentment_money.amount",

"operator":"greaterThan",

"value":100

}

To break this down:

  • The path tells us that the field in the event object which triggered this workflow which we're going to check. In our example, we're using the new order is created trigger, so we're going to be looking at the $.subtotal_price_set.presentment_money.amount field of the Order object.
  • The operator tells us that we're going to compare this field value using greaterThan , or > .
  • The value tells us that we're going to compare the field value to 100 .

Putting that all together, that means that this condition will be met if the order subtotal amount is greater than 100.

For the second condition, we have:

{

"path":"$.currency",

"operator":"equal",

"value":"GBP"

}

Using the same logic as above, we can see that this condition will be met if:

  • The value of the $.currency field in the Order object
  • Is equal to
  • "GBP"

Therefore, this workflow will only fire when a new order is created whose subtotal amount is greater than 100 and whose currency is equal to GBP.


Understanding the available fields

Each trigger that Swoop offers provides different conditions, which are all based on the information which we receive from your Shopify store when the given trigger takes place. To understand the shape of the data we receive, check out the Shopify documentation on Webhooks.

Still need help? Contact Us Contact Us