AutomationFlowsGeneral › Dynamic Search Criteria Builder

Dynamic Search Criteria Builder

Original n8n title: Search-criteria (stop and Error)

Search-Criteria. Uses noOp, stopAndError, itemLists, executeWorkflowTrigger. Event-driven trigger; 14 nodes.

Event trigger★★★★☆ complexity14 nodesStop And ErrorItem ListsExecute Workflow TriggerHTTP Request
General Trigger: Event Nodes: 14 Complexity: ★★★★☆ Added:

This workflow follows the Execute Workflow Trigger → HTTP Request recipe pattern — see all workflows that pair these two integrations.

The workflow JSON

Copy or download the full n8n JSON below. Paste it into a new n8n workflow, add your credentials, activate. Full import guide →

Download .json
{
  "nodes": [
    {
      "parameters": {},
      "id": "97bf70d8-9d47-4abf-bd75-e3d500a9be1b",
      "name": "Initial data",
      "type": "n8n-nodes-base.noOp",
      "position": [
        -520,
        720
      ],
      "executeOnce": true,
      "notesInFlow": true,
      "typeVersion": 1,
      "notes": "for reference."
    },
    {
      "parameters": {
        "errorMessage": "={{ $json[\"statusCode\"] }}: {{ JSON.stringify($json[\"body\"]) }}"
      },
      "id": "c18335f7-293f-43b7-93a5-c95880f73f72",
      "name": "Trigger error",
      "type": "n8n-nodes-base.stopAndError",
      "position": [
        680,
        720
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "amount": 5,
        "unit": "seconds"
      },
      "id": "012dc678-ae6f-4cd3-9aa8-9ece0634c922",
      "name": "Wait 5s for retry",
      "type": "n8n-nodes-base.wait",
      "position": [
        680,
        1020
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "dataType": "string",
        "value1": "={{ Math.floor($json[\"statusCode\"] / 100) }}xx",
        "rules": {
          "rules": [
            {
              "value2": "2xx"
            },
            {
              "value2": "3xx",
              "output": 1
            },
            {
              "value2": "4xx",
              "output": 2
            },
            {
              "value2": "5xx",
              "output": 3
            }
          ]
        }
      },
      "id": "61caa7c2-e779-4510-a766-65683e975aeb",
      "name": "Check response code",
      "type": "n8n-nodes-base.switch",
      "position": [
        200,
        720
      ],
      "notesInFlow": true,
      "typeVersion": 1,
      "notes": "Output: 2xx, 3xx, 4xx, 5xx"
    },
    {
      "parameters": {
        "conditions": {
          "boolean": [
            {
              "value1": "={{$json[\"body\"][\"items\"].length > 0}}",
              "value2": true
            }
          ]
        }
      },
      "id": "4305c283-2b78-4dd8-9c81-3fec40a1e38e",
      "name": "Response has items?",
      "type": "n8n-nodes-base.if",
      "position": [
        440,
        540
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "fieldToSplitOut": "body.items",
        "options": {}
      },
      "id": "4f2d7f14-74cd-4362-a65f-072bfbab81a5",
      "name": "Extract items",
      "type": "n8n-nodes-base.itemLists",
      "position": [
        680,
        320
      ],
      "notesInFlow": true,
      "typeVersion": 1
    },
    {
      "parameters": {
        "jsCode": "let allItems = [],\n    runIndexCounter = 0;\n\ndo {\n  try {\n    $('Extract items').all(0, runIndexCounter).map(item => allItems.push(item));\n  } catch (error) {\n    return allItems;\n  }\n\n  runIndexCounter++;  \n} while (true);"
      },
      "id": "655b6c3b-65a9-407c-b7d9-c61992a302c7",
      "name": "Aggregate all items",
      "type": "n8n-nodes-base.code",
      "position": [
        680,
        560
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "return {\n  \"json\": {\n    \"search_criteria\": {\n      \"filter_groups\": [\n        {\n          \"filters\": $('Initial data').item.json.filters\n        }\n      ],\n      \"sort_orders\": $('Initial data').item.json.sort_orders,\n      \"page_size\": $('Initial data').item.json.page_size,\n      \"current_page\": ($runIndex+1)\n    }\n  }\n};"
      },
      "id": "6136089b-d567-41c8-930f-da46d56c521e",
      "name": "Prepare search criteria",
      "type": "n8n-nodes-base.code",
      "position": [
        -280,
        720
      ],
      "executeOnce": true,
      "typeVersion": 1
    },
    {
      "parameters": {
        "keepOnlySet": true,
        "options": {}
      },
      "id": "67a3070e-71a7-4e1d-b78f-5ae08e7b7255",
      "name": "Reset iteration data",
      "type": "n8n-nodes-base.set",
      "position": [
        920,
        320
      ],
      "executeOnce": true,
      "typeVersion": 1,
      "alwaysOutputData": true
    },
    {
      "parameters": {
        "values": {
          "number": [
            {
              "name": "page_size",
              "value": "={{ $json[\"page_size\"] || 25 }}"
            }
          ]
        },
        "options": {}
      },
      "id": "324fa844-63aa-46ca-a516-995eda5e07bb",
      "name": "Set default page size",
      "type": "n8n-nodes-base.set",
      "position": [
        -760,
        720
      ],
      "executeOnce": true,
      "notesInFlow": true,
      "typeVersion": 1,
      "notes": "if not already set."
    },
    {
      "parameters": {
        "jsCode": "return $('Prepare search criteria').first();"
      },
      "id": "08aca0f2-f5c8-4477-b0f8-3619234b22c8",
      "name": "Restore last search criteria",
      "type": "n8n-nodes-base.code",
      "position": [
        920,
        1020
      ],
      "typeVersion": 1
    },
    {
      "parameters": {},
      "id": "727eaaa9-6ce2-4498-99f1-5eb0acbb2972",
      "name": "When Called By Another Workflow",
      "type": "n8n-nodes-base.executeWorkflowTrigger",
      "typeVersion": 1,
      "position": [
        -1020,
        720
      ]
    },
    {
      "parameters": {
        "conditions": {
          "number": [
            {
              "value1": "={{$runIndex+1}}",
              "operation": "larger",
              "value2": 5
            }
          ]
        }
      },
      "id": "71b13727-7bdb-4210-bdba-7997f8d6757e",
      "name": "Max retries reached?",
      "type": "n8n-nodes-base.if",
      "position": [
        440,
        880
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "url": "={{$env['VDSHOP_MAGENTO_API_ENDPOINT']}}/{{$('Initial data').first(0, 0).json[\"endpoint\"]}}",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendQuery": true,
        "specifyQuery": "json",
        "jsonQuery": "={{JSON.stringify($json)}}",
        "options": {
          "batching": {
            "batch": {
              "batchSize": 1,
              "batchInterval": 500
            }
          },
          "queryParameterArrays": "indices",
          "response": {
            "response": {
              "fullResponse": true,
              "neverError": true,
              "responseFormat": "json"
            }
          }
        }
      },
      "id": "03b1ae89-ff0d-4c8d-af88-bf3bbd03cad3",
      "name": "Retrieve data",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 3,
      "position": [
        -40,
        720
      ],
      "notesInFlow": true,
      "retryOnFail": true,
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      },
      "notes": "from Magento API."
    }
  ],
  "connections": {
    "Initial data": {
      "main": [
        [
          {
            "node": "Prepare search criteria",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait 5s for retry": {
      "main": [
        [
          {
            "node": "Restore last search criteria",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check response code": {
      "main": [
        [
          {
            "node": "Response has items?",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Trigger error",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Trigger error",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Max retries reached?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Response has items?": {
      "main": [
        [
          {
            "node": "Extract items",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Aggregate all items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract items": {
      "main": [
        [
          {
            "node": "Reset iteration data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare search criteria": {
      "main": [
        [
          {
            "node": "Retrieve data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Reset iteration data": {
      "main": [
        [
          {
            "node": "Prepare search criteria",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set default page size": {
      "main": [
        [
          {
            "node": "Initial data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Restore last search criteria": {
      "main": [
        [
          {
            "node": "Retrieve data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When Called By Another Workflow": {
      "main": [
        [
          {
            "node": "Set default page size",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Max retries reached?": {
      "main": [
        [
          {
            "node": "Trigger error",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Wait 5s for retry",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Retrieve data": {
      "main": [
        [
          {
            "node": "Check response code",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Credentials you'll need

Each integration node will prompt for credentials when you import. We strip credential IDs before publishing — you'll add your own.

Pro

For the full experience including quality scoring and batch install features for each workflow upgrade to Pro

How this works

This workflow streamlines the process of dynamically generating search criteria from incoming event data, enabling precise and automated querying across multiple sources without manual intervention. It suits developers and automation specialists building complex data pipelines who need reliable error handling and item aggregation to maintain data integrity. The key step involves extracting and aggregating items from responses using the itemLists node, followed by code nodes that prepare refined search criteria for downstream actions like HTTP requests.

Use this workflow when handling event-driven searches that require retry logic for failed API calls or when aggregating variable item lists into structured criteria for tools such as Google Sheets or databases. Avoid it for simple static searches lacking error-prone integrations, or when real-time processing demands exceed the 5-second wait tolerance. Common variations include adding AI nodes for criteria refinement or integrating with Slack for error notifications.

About this workflow

Search-Criteria. Uses noOp, stopAndError, itemLists, executeWorkflowTrigger. Event-driven trigger; 14 nodes.

Source: https://gitlab.com/vdshop/public/n8n-workflows/-/blob/master/workflows/data-provider/api/magento/search-criteria.json — original creator credit. Request a take-down →

More General workflows → · Browse all categories →

Related workflows

Workflows that share integrations, category, or trigger type with this one. All free to copy and import.

General

Prevent concurrent workflow runs using Redis. Uses executeWorkflowTrigger, manualTrigger, stickyNote, executeWorkflow. Event-driven trigger; 43 nodes.

Execute Workflow Trigger, Redis, Stop And Error
General

This workflow sets a small "lock" value in Redis so that only one copy of a long job can run at the same time. If another trigger fires while the job is still busy, the workflow sees the lock, stops e

Execute Workflow Trigger, Redis, Stop And Error
General

Reputation Engine — Site Refresh. Uses httpRequest, executeWorkflowTrigger. Event-driven trigger; 35 nodes.

HTTP Request, Execute Workflow Trigger
General

This template facilitates the transfer of a folder, along with all its files and subfolders, within a Nextcloud instance. The Nextcloud user must have access to both the source and destination folders

Execute Workflow Trigger, Next Cloud, Stop And Error
General

PRECALL. Uses executeWorkflowTrigger, httpRequest. Event-driven trigger; 23 nodes.

Execute Workflow Trigger, HTTP Request