{
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "c8edaab9-0dda-4c1f-88fe-e9dec377e72b",
      "name": "Session Memory2",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        848,
        2144
      ],
      "parameters": {
        "sessionKey": "={{ $now.minute }}",
        "sessionIdType": "customKey",
        "contextWindowLength": 10
      },
      "typeVersion": 1.3
    },
    {
      "id": "982f9886-40c8-45f8-a21b-a4228632ef9a",
      "name": "Structured Output Parser",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        1184,
        2032
      ],
      "parameters": {
        "autoFix": true,
        "jsonSchemaExample": "{\n\"product_id\" : 456789,\n\"product_title\" : \"13456 LT\",\n\"generated_description\" :\" The description goes here\",\n\"status\": \"generated,retry\"\n\n\n}"
      },
      "typeVersion": 1.3
    },
    {
      "id": "705e2c44-6286-48d9-aa97-c7b220df51fb",
      "name": "Analyze image",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        272,
        1776
      ],
      "parameters": {
        "text": "=From the product image, identify only the *visible physical attributes* of the footwear. Avoid inferring features that are not clearly visible.\n\nReturn a short descriptive summary (max 50 words) strictly based on observable traits. Focus on the following, only if clearly identifiable:\n\n- Does the shoe have **adjustability**? (e.g. velcro, buckles, elastic inserts, laces)\n- Describe the **closure type** (e.g. slingback, buckle, slip-on, full coverage).\n- Is there any **heel presence/height** and what is its shape (block, wedge, flared)?\n- Upper material: leather, suede, woven, etc.\n- Sole type (e.g. rubber, smooth, textured).\n- Pointed/round toe.\n- Any visible cushioning, traction features or contours.\n\n\u26a0\ufe0f DO NOT mention colour, logos, or branding. Only describe what can be physically seen.",
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o",
          "cachedResultName": "GPT-4O"
        },
        "options": {},
        "resource": "image",
        "imageUrls": "={{ $json['Image url'] }}",
        "operation": "analyze"
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.8
    },
    {
      "id": "ee48f02a-4913-4b1f-954f-f82e50a66460",
      "name": "OpenRouter Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenRouter",
      "position": [
        640,
        2064
      ],
      "parameters": {
        "model": "anthropic/claude-3.5-sonnet",
        "options": {}
      },
      "credentials": {
        "openRouterApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "27bc6657-eb1c-442b-b479-e5a2371597e2",
      "name": "OpenRouter Chat Model1",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenRouter",
      "position": [
        1376,
        2208
      ],
      "parameters": {
        "options": {}
      },
      "credentials": {
        "openRouterApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "bd7b15cf-9f24-4867-8f27-8b6dc6b69a88",
      "name": "Error Trigger",
      "type": "n8n-nodes-base.errorTrigger",
      "position": [
        -192,
        2384
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "de711274-f02b-4ca4-a3b7-c2c9376566ea",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        240,
        2384
      ],
      "parameters": {
        "text": "=error_message : {{ $json.execution.error.message }}\n",
        "options": {
          "systemMessage": "=You are a smart workflow error analyst and logger built into an n8n automation system. When a workflow fails, your job is to:\n\n1. **Understand the root cause of an error.**\n2. **Search external sources using Perplexity for additional insights.**\n3. **Explain the error clearly\u2014first in layman's terms, then support it with technical context.**\n4. **Log the final explanation into the `Reason of Error` column of a Google Sheet.**\n\n---\n\n### \ud83d\udd0d Step 1: Understand the Error Input\n\nYou will receive an error event via the `Error Trigger`. This contains metadata like:\n- The workflow or node name where the error occurred\n- The full error message (stack trace if available)\n\nYour job is to **diagnose** what happened and which n8n node or integration was responsible for the failure.\n\n---\n\n### \ud83d\udd0e Step 2: AI-Powered Troubleshooting\n\nIf the issue is unclear, run a research query using Perplexity:\n- Use the error message as the query.\n- From the search results, find and summarise only the most **relevant solution** or explanation.\n- Prefer sources from platforms like [n8n.io](https://community.n8n.io), [Stack Overflow](https://stackoverflow.com), or dev blogs.\n\n---\n\n### \ud83d\udc69\u200d\ud83c\udfeb Step 3: Write the Explanation\n\nCraft a **clear and helpful response** in the following structure:\n\n#### \u27a4 Format:\nReason of Error: { Explanation }\n\n\n\n#### \u27a4 Guidelines:\n- Start with an **easy-to-understand (layman)** explanation, e.g.:\n  > \u201cThe automation tried to connect to Google Sheets but failed because it couldn\u2019t identify which row to update.\u201d\n\n- Then follow with **technical insight**, e.g.:\n  > \u201cThis is typically caused by a missing `Product ID` or unmatched row key, leading to an `IndexOutOfRangeException`. See [dev.to](https://dev.to/iamcymentho/understanding-indexoutofrangeexception-in-c-2k5g) for context.\u201d\n\n- Always include the suspected **node name** and **likely fix** if known.\n\n- Sign your explanation with a reference link if the cause is verified externally, like:\n  > *Learn more: [dev.to](https://dev.to/iamcymentho/understanding-indexoutofrangeexception-in-c-2k5g)*\n\n---\n\n### \ud83d\udccb Step 4: Output (Structured for Sheet Logging)\n\nUpdate the Google Sheet (`Error_log`) using:\n- `row_number` (pre-calculated by n8n)\n- `timestamp`: Use current time\n- `Reason of Error`: Write your combined explanation here\n\n\ud83d\uded1 **Do NOT return the actual content as code blocks or markdown.** Google Sheets expects raw strings.\n\n---\n\n### \u274c What NOT to include:\n- Do **not** return full stack traces to the sheet.\n- Do **not** guess without explanation.\n- Do **not** add unrelated suggestions.\n\n---\n\n### \u2705 Example Output:\n\n**Reason of Error**:\n> The workflow attempted to update a row in Google Sheets, but couldn't find a match.  \n> This likely happened because the \"Product ID\" was missing or incorrect, resulting in an index error. Technically, this is called an `IndexOutOfRangeException` \u2014 it means the script tried to work with a row that doesn't exist.  \n> Learn more: [dev.to](https://dev.to/iamcymentho/understanding-indexoutofrangeexception-in-c-2k5g)\n\n**Timestamp**: Automatically insert current time  \n**Row_number**: Already mapped\n\n"
        },
        "promptType": "define"
      },
      "typeVersion": 2.1
    },
    {
      "id": "4745e47b-8b90-4df4-8f51-c0f9a4c89950",
      "name": "OpenRouter Chat Model2",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenRouter",
      "position": [
        -144,
        2640
      ],
      "parameters": {
        "options": {}
      },
      "credentials": {
        "openRouterApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "26ce222a-eac0-487e-8bba-faf3cbff995b",
      "name": "Simple Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        128,
        2688
      ],
      "parameters": {
        "sessionKey": "={{ $now.minute }}",
        "sessionIdType": "customKey"
      },
      "typeVersion": 1.3
    },
    {
      "id": "516b8add-06a1-4ad7-a549-f135adbbe33e",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1072,
        976
      ],
      "parameters": {
        "color": 7,
        "width": 608,
        "height": 1008,
        "content": "# Shopify Product Description agent \n\n\n## Pagination Handling\n\n\n1. schedule every hour \n2. Search if there has already been run from the previous attempt or not if there has been previous run it will start from the latest product id.\n\n3. Code node will filter the products fetched each time to check whether it has body_html , CurrSeas:SS2025 or it has image then it process \n\n4. The Open Ai image node will do the descriptions of image based on the image link. and feed it to the main agent\n\n5. The main agent or the content creator will write the product description according to the AU format.\n\n6. The output format for the main agent is mainly all the fields id,vendor,generated description, status etc.\n\n7. The second code node keeps record of next page url to continue from there and record it in the sheet.\n\n"
      },
      "typeVersion": 1
    },
    {
      "id": "5f2a3b8b-11e6-4955-8b9c-814416406540",
      "name": "Message a model in Perplexity",
      "type": "n8n-nodes-base.perplexityTool",
      "position": [
        1072,
        2112
      ],
      "parameters": {
        "model": "sonar",
        "options": {},
        "messages": {
          "message": [
            {
              "content": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('message0_Text', ``, 'string') }}"
            }
          ]
        },
        "requestOptions": {}
      },
      "credentials": {
        "perplexityApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "c14c3978-293b-440b-a6f9-389f3e256aa1",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1008,
        2320
      ],
      "parameters": {
        "color": 2,
        "width": 640,
        "height": 208,
        "content": "# Error Notification \n\n\n###  If there is any error related to Api or server error mainly it will notify the owner about the type fo the error and explain the reason\n\n"
      },
      "typeVersion": 1
    },
    {
      "id": "36bdcdbd-76b0-46ab-b1a2-1ab8d04abbe7",
      "name": "Message a model in Perplexity1",
      "type": "n8n-nodes-base.perplexityTool",
      "position": [
        464,
        2720
      ],
      "parameters": {
        "model": "sonar",
        "options": {},
        "messages": {
          "message": [
            {
              "content": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('message0_Text', ``, 'string') }}"
            }
          ]
        },
        "requestOptions": {}
      },
      "credentials": {
        "perplexityApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "e938da49-2aa9-4896-a01c-0af2b372f7d9",
      "name": "Shopify Content Generator",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "notes": "FIXED: Output format to match sheets mapping",
      "position": [
        880,
        1776
      ],
      "parameters": {
        "text": "=\n\n\nProduct id : {{ $json['Product ID'] }}\nProduct Title :{{ $json['Product Title'] }}\nProduct Type:{{ $json['Product Type'] }}\nVendor: {{ $json.Vendor }}\nimage_description:{{ $json.content }}\nstatus : {{ $json.Status }}\ncountry_of_origin: {{ $('Limit1').item.json['country of origin'] }}\nx_style_code :{{ $('Limit1').item.json.x_style_code }}\ngender: {{ $('Limit1').item.json.gender }}",
        "options": {
          "systemMessage": "=You are a luxury footwear copywriter for Peter Sheppard Footwear \u2014 Australia\u2019s destination for premium European footwear. Default audience is modern women aged 60+, prioritising longevity, comfort, and sophistication. If gender contains \u201cMen\u201d or \u201cMens\u201d, write for men with the same refined tone.\n\nGOAL\nWrite SEO-aware, benefit-led Shopify product descriptions (60\u201380 words, 2\u20133 sentences) that reflect the shoe\u2019s identity while remaining strictly factual to the provided AI Vision Output. Do NOT mention colour.\n\nINPUT (context from workflow)\n\u2022\u2060  \u2060Product ID: {{ $json[\"Product ID\"] }}\n\u2022\u2060  \u2060Product Title: {{ $json[\"Product Title\"] }}\n\u2022\u2060  \u2060Product Type: {{ $json[\"Product Type\"] }}\n\u2022\u2060  \u2060Vendor: {{ $json[\"Vendor\"] }}\n\u2022\u2060  \u2060AI Vision Output (observable traits only): {{ $json[\"content\"] }}\n\u2022\u2060  \u2060Status: {{ $json[\"Status\"] }}\n\u2022\u2060  \u2060Country of Origin: {{ $('Limit1').item.json['country of origin'] }}\n\u2022\u2060  \u2060Style Code: {{ $('Limit1').item.json.x_style_code }}\n\u2022\u2060  \u2060Gender: {{ $('Limit1').item.json.gender }}\n\nOUTPUT FORMAT\nReturn one JSON object only (no markdown, no extra text).\n\nIf successful:\n{\n  \"product_id\": \"{{ $json['Product ID'] }}\",\n  \"product_title\": \"{ cleaned_title with all colours removed }\",\n  \"generated_description\": \"{ 60\u201380 words; first sentence includes origin/design-country rule; includes Style Code if provided; only image-verified traits; refined, concise, mobile-friendly; Australian English }\",\n  \"status\": \"generated\"\n}\n\nIf generation fails (see Fail Conditions below):\n{\n  \"product_id\": \"{{ $json['Product ID'] }}\",\n  \"product_title\": \"{ cleaned_title with all colours removed }\",\n  \"generated_description\": \"\",\n  \"status\": \"retry\"\n}\n\nCRITICAL RULES\n1) Colour Removal\n\u2022\u2060  \u2060Remove all colour words/hints from both product_title and description.\n\u2022\u2060  \u2060Do not imply colour via metaphor or material cues.\n\n2) Origin vs Design Country Logic\n\u2022\u2060  \u2060If Country of Origin is provided and non-empty, include it in the first sentence:\n  - Default phrasing: \u201cMade in {Country of Origin}, \u2026\u201d\n  - Exceptions \u2014 do NOT state the country of origin if origin is outside of Europe\u201d:\n    \u2022 If COO is Vietnam\n    \u2022 If COO is China\n    \u2022 If COO is India\n    \u2022 If COO contains both Spain and China in any order or formatting (e.g., \u201cSpain/China\u201d, \u201cChina / Spain\u201d) \u2192 \u201cDesigned in Spain, \u2026\u201d\n\u2022\u2060  \u2060If Country of Origin is missing:\n  - Use the integrated Perplexity tool to identify the vendor\u2019s official Country of Design (only from official sources: brand website, corporate pages, trademarks, LinkedIn).\n  - Include design country ONLY if certain; otherwise omit origin/design entirely.\n  - Never include citations or source names in the output.\n\n3) Style Code Placement\n\u2022\u2060  \u2060If Style Code exists ({{ $('Limit1').item.json.x_style_code }}), include it in the first sentence adjacent to Vendor and shoe type:\n  - Examples: \u201cthe {Vendor} {StyleCode} {shoe type} \u2026\u201d or \u201cthe {StyleCode} {Vendor} {shoe type} \u2026\u201d\n\u2022\u2060  \u2060Do NOT add style code to product_title unless it already appears there.\n\n4) Image-Based Feature Usage (STRICT)\n\u2022\u2060  \u2060Use ONLY traits explicitly present in AI Vision Output (no speculation).\n\u2022\u2060  \u2060Include, if clearly visible:\n  - Closure type: velcro, zipper, buckle, lace-up, slip-on, slingback, elastic gussets\n  - Upper material: leather, suede, mesh, woven, textile\n  - Footbed: contoured, removable, cushioned, leather-lined (only if evidently shown)\n  - Heel: low, block, wedge, flared (if apparent)\n  - Sole: textured, rubber, flat (if visible)\n  - Adjustability: ONLY if velcro/buckle/elastic/strap is clearly evident\n\u2022\u2060  \u2060If a feature is not confirmed, omit it.\n\n5) Tone & Style\n\u2022\u2060  \u2060Sophisticated, elegant, succinct, mobile-first.\n\u2022\u2060  \u2060Benefit-led without clich\u00e9s; vary cadence; avoid filler.\n\u2022\u2060  \u2060Use Australian English (e.g., favour, organise, lining).\n\n6) SEO\n\u2022\u2060  \u2060Naturally include vendor and product type.\n\u2022\u2060  \u2060Keep phrasing concise and unique per item.\n\n7) Prohibited\n\u2022\u2060  \u2060Any colour mention or inference.\n\u2022\u2060  \u2060The word \u201cdiscerning.\u201d\n\u2022\u2060  \u2060References to \u201cAustralian woman\u201d (use \u201cmodern woman\u201d/\u201cmodern man\u201d if needed).\n\u2022\u2060  \u2060Guesswork or unsupported materials/features.\n\u2022\u2060  \u2060\u201cPatent leather\u201d or artificial materials unless part of a brand name.\n\nGENDER HANDLING\n\u2022\u2060  \u2060If Gender contains \u201cMen\u201d or \u201cMens\u201d, adopt a men\u2019s perspective and benefit language while maintaining the same premium tone.\n\u2022\u2060  \u2060Otherwise, assume women\u2019s.\n\nFAIL CONDITIONS (return status=retry)\n\u2022\u2060  \u2060AI Vision Output is missing/empty or too generic to support a factual 60\u201380 word description.\n\u2022\u2060  \u2060You cannot confidently confirm any physical features from the image description.\n\u2022\u2060  \u2060The origin/design country cannot be confirmed when required by logic, and its omission would leave the first sentence awkward or misleading.\n\u2022\u2060  \u2060Any irreconcilable conflict between rules.\n\nQUALITY CHECK BEFORE OUTPUT\n\u2022\u2060  \u2060Title cleaned of all colours.\n\u2022\u2060  \u2060First sentence: origin/design-country rule applied correctly (or omitted if uncertain and COO missing).\n\u2022\u2060  \u2060Style code included in the first sentence if provided (not injected into the title unless already present).\n\u2022\u2060  \u2060Only image-verified features included.\n\u2022\u2060  \u206060\u201380 words, Australian English, refined tone.\n\u2022\u2060  \u2060No prohibited terms or colour references.\n\u2022\u2060  \u2060JSON only, no extra text or markdown.\n\nSTYLE EXAMPLES\nA (design tradition + code):\nFrom Spain\u2019s Mediterranean craftsmanship tradition, the Pikolinos 06J-5433 sandal offers full-coverage ease with breathable openings. The leather upper and hook-and-loop adjustability provide a personalised, secure fit, while a textured sole enhances everyday traction. Subtle contouring supports comfort and longevity with refined, travel-ready practicality.\n\nB (made-in + code):\nMade in Hungary, the 1622102 Hartjes Mary Jane balances elegance and practicality. An adjustable velcro strap secures the fit, the smooth leather upper and rounded toe feel accommodating, and the flat, textured sole promotes stability. Considered details reflect orthopaedic expertise shaped for long-wearing comfort."
        },
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 2.1
    },
    {
      "id": "3dc1131c-7ef4-4ffb-8f7b-190a2aacdac5",
      "name": "Get row(s) in sheet1",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -208,
        1776
      ],
      "parameters": {
        "options": {},
        "filtersUI": {
          "values": [
            {
              "lookupValue": "Ready for AI Description",
              "lookupColumn": "Status"
            }
          ]
        },
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 1133377362,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1r1lnORqg8lyGdZCOReGAd-ND2MTYF5gMKJBUH-n00ME/edit#gid=1133377362",
          "cachedResultName": "Products"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1r1lnORqg8lyGdZCOReGAd-ND2MTYF5gMKJBUH-n00ME",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1r1lnORqg8lyGdZCOReGAd-ND2MTYF5gMKJBUH-n00ME/edit?usp=drivesdk",
          "cachedResultName": "Shopify Processing Sheet"
        },
        "combineFilters": "OR"
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.6
    },
    {
      "id": "3913bbb9-a333-45c3-9847-62a839854d05",
      "name": "Limit1",
      "type": "n8n-nodes-base.limit",
      "position": [
        32,
        1776
      ],
      "parameters": {
        "maxItems": 10
      },
      "typeVersion": 1
    },
    {
      "id": "5c0fd73c-7893-41d1-8fd4-869c10f398e2",
      "name": "Every 5 Minutes",
      "type": "n8n-nodes-base.cron",
      "position": [
        -384,
        1056
      ],
      "parameters": {
        "triggerTimes": {
          "item": [
            {
              "mode": "custom",
              "cronExpression": "*/5 * * * *"
            }
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "id": "cc08369a-de12-4bc2-9c5e-7b59221a4576",
      "name": "Fetch Shopify Products",
      "type": "n8n-nodes-base.httpRequest",
      "notes": "Fixed: API 2024-04, fullResponse enabled, conditional pagination",
      "position": [
        128,
        1056
      ],
      "parameters": {
        "url": "https://peter-sheppard.myshopify.com/admin/api/2024-04/products.json",
        "options": {
          "response": {
            "response": {
              "neverError": true,
              "fullResponse": true
            }
          }
        },
        "sendQuery": true,
        "authentication": "predefinedCredentialType",
        "queryParameters": {
          "parameters": [
            {
              "name": "limit",
              "value": "200"
            },
            {
              "name": "page_info",
              "value": "={{ $json.page_info_next }}"
            }
          ]
        },
        "nodeCredentialType": "shopifyAccessTokenApi"
      },
      "credentials": {
        "shopifyAccessTokenApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "10e9dc48-18b9-4710-915b-b8b85d23b72c",
      "name": "Get row(s) in sheet2",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -160,
        1056
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1r1lnORqg8lyGdZCOReGAd-ND2MTYF5gMKJBUH-n00ME/edit#gid=0",
          "cachedResultName": "ProcessingState"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1r1lnORqg8lyGdZCOReGAd-ND2MTYF5gMKJBUH-n00ME",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1r1lnORqg8lyGdZCOReGAd-ND2MTYF5gMKJBUH-n00ME/edit?usp=drivesdk",
          "cachedResultName": "Shopify Processing Sheet"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.6
    },
    {
      "id": "96d23e37-694e-4018-a7ec-f315047d10fc",
      "name": "Code5",
      "type": "n8n-nodes-base.code",
      "position": [
        160,
        1376
      ],
      "parameters": {
        "jsCode": "// Extract page_info from Link header for pagination - FIXED for multiple links\nconst items = $input.all();\nlet pageInfo = null;\nlet linkHeader = null;\nlet debugInfo = {};\n\nfor (const item of items) {\n  // Log the structure for debugging\n  debugInfo.itemKeys = Object.keys(item.json);\n  \n  // Try different possible locations for headers\n  if (item.json.headers) {\n    linkHeader = item.json.headers.link || item.json.headers.Link || item.json.headers['link'] || item.json.headers['Link'];\n    debugInfo.headersFound = true;\n    debugInfo.headerKeys = Object.keys(item.json.headers);\n  } else if (item.json.response && item.json.response.headers) {\n    linkHeader = item.json.response.headers.link || item.json.response.headers.Link;\n    debugInfo.responseHeadersFound = true;\n  } else if (item.json.header) {\n    linkHeader = item.json.header.link || item.json.header.Link;\n    debugInfo.headerFound = true;\n  }\n  \n  if (linkHeader) {\n    debugInfo.linkHeaderFound = linkHeader;\n    break;\n  }\n}\n\nif (linkHeader) {\n  debugInfo.rawLinkHeader = linkHeader;\n  \n  // FIXED: Handle multiple links by splitting on comma first\n  const linkParts = linkHeader.split(',').map(part => part.trim());\n  debugInfo.linkParts = linkParts;\n  \n  // Find the \"next\" link specifically\n  for (const linkPart of linkParts) {\n    debugInfo.processingPart = linkPart;\n    \n    // Check if this part contains rel=\"next\"\n    if (/rel=[\"']?next[\"']?/i.test(linkPart)) {\n      debugInfo.foundNextLink = linkPart;\n      \n      // Extract the URL from this specific \"next\" link part\n      const urlMatch = linkPart.match(/<([^>]+)>/);\n      if (urlMatch && urlMatch[1]) {\n        try {\n          const url = new URL(urlMatch[1]);\n          pageInfo = url.searchParams.get('page_info');\n          debugInfo.extractedUrl = urlMatch[1];\n          debugInfo.extractedPageInfo = pageInfo;\n          break;\n        } catch (error) {\n          debugInfo.urlParseError = error.message;\n        }\n      }\n    }\n  }\n  \n  // Fallback: if no page_info found, try direct extraction\n  if (!pageInfo) {\n    // Look for page_info parameter in any \"next\" link\n    for (const linkPart of linkParts) {\n      if (/rel=[\"']?next[\"']?/i.test(linkPart)) {\n        const pageInfoMatch = linkPart.match(/page_info=([^&>\\s]+)/i);\n        if (pageInfoMatch) {\n          pageInfo = pageInfoMatch[1];\n          debugInfo.directExtraction = true;\n          debugInfo.extractedFrom = linkPart;\n          break;\n        }\n      }\n    }\n  }\n}\n\n// Return the page info with debug information\nreturn [{\n  json: {\n    page_info: pageInfo,\n    page_info_next: pageInfo, // Keep both for compatibility\n    has_next_page: pageInfo !== null,\n    debug: debugInfo,\n    raw_link_header: linkHeader\n  }\n}];"
      },
      "typeVersion": 2
    },
    {
      "id": "4ec04e2c-c232-41d0-a4b4-38f3d657a172",
      "name": "Update row in sheet1",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        800,
        1360
      ],
      "parameters": {
        "columns": {
          "value": {
            "row_number": 2,
            "batch number": "={{ $json['batch number'] }}",
            "page_info_next": "={{ $json.page_info }}"
          },
          "schema": [
            {
              "id": "batch number",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "batch number",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "page_info_next",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "page_info_next",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "row_number",
              "type": "number",
              "display": true,
              "removed": false,
              "readOnly": true,
              "required": false,
              "displayName": "row_number",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "row_number"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "update",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.YOUR_AWS_SECRET_KEY_HERE-ND2MTYF5gMKJBUH-n00ME/edit#gid=0",
          "cachedResultName": "ProcessingState"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1r1lnORqg8lyGdZCOReGAd-ND2MTYF5gMKJBUH-n00ME",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1r1lnORqg8lyGdZCOReGAd-ND2MTYF5gMKJBUH-n00ME/edit?usp=drivesdk",
          "cachedResultName": "Shopify Processing Sheet"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.6
    },
    {
      "id": "352f95c9-9f13-4206-927c-65fd7f3d578f",
      "name": "Edit Fields1",
      "type": "n8n-nodes-base.set",
      "position": [
        624,
        1360
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "db8a85c3-6d48-4e0d-a5db-101ff6afa135",
              "name": "batch number",
              "type": "number",
              "value": "={{ $('Get row(s) in sheet2').item.json['batch number'] + 1 }} "
            },
            {
              "id": "e3044479-8b26-445a-b8c6-536e083749c0",
              "name": "page_info",
              "type": "string",
              "value": "={{ $json.page_info }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "acf231ef-e8ff-49c7-bfb5-47f5db52d7ac",
      "name": "If2",
      "type": "n8n-nodes-base.if",
      "position": [
        368,
        1376
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "70594865-5674-4179-9b16-7198ec9b57d3",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              },
              "leftValue": "={{ $json.has_next_page }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "aba69031-9b64-485a-8f9d-f0c58b17c6b3",
      "name": "Limit2",
      "type": "n8n-nodes-base.limit",
      "position": [
        1072,
        1040
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "3ad6e0e0-863b-4205-b284-2a65da7f49d9",
      "name": "Append row in sheet2",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        800,
        1040
      ],
      "parameters": {
        "columns": {
          "value": {
            "Status": "={{ $json.Status }}",
            "Vendor": "={{ $json.Vendor }}",
            "gender": "={{ $json.gender }}",
            "Image url": "={{ $json['Image URL'] }}",
            "Product ID": "={{ $json['Product ID'] }}",
            "Product Type": "={{ $json['Product Type'] }}",
            "x_style_code": "={{ $json[\"x-styleCode\"] }}",
            "Filter Reason": "={{ $json['Filter Reason'] }}",
            "Product Title": "={{ $json['Product Title'] }}",
            "country of origin": "={{ $json.country_of_origin }}"
          },
          "schema": [
            {
              "id": "Product ID",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Product ID",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Product Title",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Product Title",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "country of origin",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "country of origin",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "x_style_code",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "x_style_code",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "gender",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "gender",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Product Type",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Product Type",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Vendor",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Vendor",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Generated Description",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Generated Description",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Filter Reason",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Filter Reason",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Status",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Status",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Image url",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Image url",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Corrected description",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Corrected description",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "is available ?",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "is available ?",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 1133377362,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1r1lnORqg8lyGdZCOReGAd-ND2MTYF5gMKJBUH-n00ME/edit#gid=1133377362",
          "cachedResultName": "Products"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1r1lnORqg8lyGdZCOReGAd-ND2MTYF5gMKJBUH-n00ME",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1r1lnORqg8lyGdZCOReGAd-ND2MTYF5gMKJBUH-n00ME/edit?usp=drivesdk",
          "cachedResultName": "Shopify Processing Sheet"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.6
    },
    {
      "id": "1f8e831c-75f1-47b3-9e4f-7f4dded2cdf3",
      "name": "If3",
      "type": "n8n-nodes-base.if",
      "position": [
        544,
        1056
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "ff2b7f86-c7e4-4254-a607-6c741e9b46aa",
              "operator": {
                "type": "number",
                "operation": "notEmpty",
                "singleValue": true
              },
              "leftValue": "={{ $json['Product ID'] }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "92bcb484-cb19-450c-a274-50e6efee8d18",
      "name": "Schedule Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -272,
        1584
      ],
      "parameters": {
        "rule": {
          "interval": [
            {}
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "07bd68b3-d4ed-4a8d-a8a4-95ad2e93c17a",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -336,
        848
      ],
      "parameters": {
        "color": 5,
        "width": 512,
        "content": "## Pagination Handler\n\nworking code\n"
      },
      "typeVersion": 1
    },
    {
      "id": "075f692e-6a79-4bd5-b30f-efdeb5bef65a",
      "name": "Update row in sheet",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1424,
        1776
      ],
      "parameters": {
        "columns": {
          "value": {
            "Status": "={{ $json.output.status }}",
            "Product ID": "={{ $json.output.product_id }}",
            "Product Title": "={{ $json.output.product_title }}",
            "Generated Description": "={{ $json.output.generated_description }}"
          },
          "schema": [
            {
              "id": "Product ID",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Product ID",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Product Title",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Product Title",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "country of origin",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "country of origin",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "x_style_code",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "x_style_code",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Product Type",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Product Type",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Vendor",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Vendor",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Generated Description",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Generated Description",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Filter Reason",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Filter Reason",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Status",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Status",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Image url",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Image url",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Corrected description",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Corrected description",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "is available ?",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "is available ?",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "row_number",
              "type": "number",
              "display": true,
              "removed": true,
              "readOnly": true,
              "required": false,
              "displayName": "row_number",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "Product ID"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "update",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 1133377362,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1r1lnORqg8lyGdZCOReGAd-ND2MTYF5gMKJBUH-n00ME/edit#gid=1133377362",
          "cachedResultName": "Products"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1r1lnORqg8lyGdZCOReGAd-ND2MTYF5gMKJBUH-n00ME",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1r1lnORqg8lyGdZCOReGAd-ND2MTYF5gMKJBUH-n00ME/edit?usp=drivesdk",
          "cachedResultName": "Shopify Processing Sheet"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.6
    },
    {
      "id": "0a2fe3c3-7684-4779-9f34-e8b8e426b78d",
      "name": "Append row in sheet in Google Sheets",
      "type": "n8n-nodes-base.googleSheetsTool",
      "position": [
        656,
        2608
      ],
      "parameters": {
        "columns": {
          "value": {
            "timestamp": "={{ $now }}",
            "Reason of Error": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Reason_of_Error', ``, 'string') }}"
          },
          "schema": [
            {
              "id": "timestamp",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "timestamp",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Reason of Error",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Reason of Error",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "Product ID"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 1502107571,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1r1lnORqg8lyGdZCOReGAd-ND2MTYF5gMKJBUH-n00ME/edit#gid=1502107571",
          "cachedResultName": "Error_log"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1r1lnORqg8lyGdZCOReGAd-ND2MTYF5gMKJBUH-n00ME",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1r1lnORqg8lyGdZCOReGAd-ND2MTYF5gMKJBUH-n00ME/edit?usp=drivesdk",
          "cachedResultName": "Shopify Processing Sheet"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "7350121a-24da-45e4-a9ae-68a2943c723d",
      "name": "Edit Fields",
      "type": "n8n-nodes-base.set",
      "position": [
        496,
        1776
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "7c0530d2-272f-45ee-b23e-c5d78863426a",
              "name": "content",
              "type": "string",
              "value": "={{ $json.content }}"
            },
            {
              "id": "8c453257-ec62-4ece-af58-41677da4980d",
              "name": "Product ID",
              "type": "string",
              "value": "={{ $('Limit1').item.json['Product ID'] }}"
            },
            {
              "id": "16c83f21-e0c4-4acc-8d0c-12f39c7dafb8",
              "name": "Product Title",
              "type": "string",
              "value": "={{ $('Limit1').item.json['Product Title'] }}"
            },
            {
              "id": "5b967666-af7a-470a-a100-7b180cbda920",
              "name": "Vendor",
              "type": "string",
              "value": "={{ $('Limit1').item.json.Vendor }}"
            },
            {
              "id": "5793a744-0be2-4d9e-9a24-08737874e5ea",
              "name": "Product Type",
              "type": "string",
              "value": "={{ $('Limit1').item.json['Product Type'] }}"
            },
            {
              "id": "c2599f79-977c-442b-b195-f5b95b16c979",
              "name": "Status",
              "type": "string",
              "value": "={{ $('Limit1').item.json.Status }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "2d983e0c-02b0-4aab-bc74-22f10bf76c54",
      "name": "When clicking \u2018Execute workflow\u2019",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        -192,
        2064
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "4417c698-2ea2-4145-ba19-74937e24cc75",
      "name": "Code1",
      "type": "n8n-nodes-base.code",
      "position": [
        320,
        1056
      ],
      "parameters": {
        "jsCode": "// Filter products - Must have image AND empty body_html AND currSeas:SS2025 tag (ALL mandatory)\n// Enhanced with duplicate prevention + tag extraction for x-styleCode, country_of_origin, and gender\nconst filteredProducts = [];\nconst processedProductIds = new Set();\n\n// Helper: extract \"key:value\" from comma-separated tags string (case-insensitive key)\nfunction getTagValue(tags, key) {\n  if (!tags) return '';\n  const tagStr = Array.isArray(tags) ? tags.join(',') : String(tags);\n  const parts = tagStr.split(',').map(t => t.trim()).filter(Boolean);\n  const lowerKey = key.toLowerCase();\n  for (const part of parts) {\n    const [k, ...rest] = part.split(':');\n    if (!k) continue;\n    if (k.trim().toLowerCase() === lowerKey) {\n      return rest.join(':').trim(); // keep value as-is; supports extra colons in value\n    }\n  }\n  return '';\n}\n\nfor (const item of $input.all()) {\n  // Add null checking for nested properties\n  if (!item || !item.json || !item.json.body) {\n    continue;\n  }\n  \n  // Products are inside body property\n  const products = item.json.body.products || [];\n  \n  if (!Array.isArray(products)) {\n    continue;\n  }\n  \n  for (const product of products) {\n    // Add null checking for product object\n    if (!product || !product.id) continue;\n    \n    // Skip if we've already processed this product ID\n    if (processedProductIds.has(product.id)) {\n      continue;\n    }\n    \n    // Mark as processed\n    processedProductIds.add(product.id);\n    \n    // Check if body_html is empty\n    const hasEmptyBodyHtml = !product.body_html || product.body_html.trim() === '';\n    \n    // Check if images exist and have valid src\n    const hasValidImage = product.images &&\n                         Array.isArray(product.images) &&\n                         product.images.length > 0 && \n                         product.images[0] && \n                         product.images[0].src && \n                         product.images[0].src.trim() !== '';\n    \n    // Check for currSeas:SS2025 tag (case insensitive)\n    const tags = product.tags || '';\n    const hasCurrentSeasonTag = /currseas:\\s*ss2025/i.test(tags);\n    \n    // Process ONLY if: has valid image AND empty body_html AND has season tag (ALL mandatory)\n    if (hasValidImage && hasEmptyBodyHtml && hasCurrentSeasonTag) {\n      // Extract additional fields from tags\n      const styleCode = getTagValue(tags, 'x-styleCode');\n      const countryOfOrigin = getTagValue(tags, 'country_of_origin');\n      const gender = getTagValue(tags, 'gender'); // NEW: gender:Mens, etc.\n\n      filteredProducts.push({\n        \"Product ID\": product.id,\n        \"Product Title\": product.title,\n        \"Product Type\": product.product_type,\n        \"Vendor\": product.vendor,\n        \"Tags\": product.tags,\n        \"x-styleCode\": styleCode,\n        \"country_of_origin\": countryOfOrigin,\n        \"gender\": gender,                         // NEW column\n        \"Image URL\": product.images[0].src,\n        \"Current Description\": product.body_html || '',\n        \"Has Valid Image\": hasValidImage,\n        \"Has Empty Body\": hasEmptyBodyHtml,\n        \"Has Season Tag\": hasCurrentSeasonTag,\n        \"Filter Reason\": \"Has valid image + Empty body_html + Has currSeas:SS2025 tag\",\n        \"Status\": \"Ready for AI Description\",\n        \"Processing Timestamp\": new Date().toISOString()\n      });\n    }\n  }\n}\n\n// Return ONLY filtered products (empty array if none match)\nreturn filteredProducts;"
      },
      "typeVersion": 2
    },
    {
      "id": "cf20bb5d-c904-4f89-8bc4-347fc41b9e59",
      "name": "Schedule Trigger1",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        1520,
        1248
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "triggerAtHour": 14,
              "triggerAtMinute": 1
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "152e5586-28ff-48eb-bdb6-d9c1e387a44a",
      "name": "HTTP Request1",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1760,
        1248
      ],
      "parameters": {
        "url": "https://re3-shop.myshopify.com/admin/api/2024-04/orders.json\n\n",
        "options": {},
        "sendQuery": true,
        "authentication": "predefinedCredentialType",
        "queryParameters": {
          "parameters": [
            {
              "name": "processed_at_min",
              "value": "={{ $now.setZone('Australia/Melbourne').minus({days: 1}).startOf('day') }}\n\n\n\n\n"
            },
            {
              "name": "processed_at_max",
              "value": "={{ $now.setZone('Australia/Melbourne').minus({days: 1}).set({ hour: 23, minute: 59, second: 59, millisecond: 999 }) }}\n\n"
            },
            {
              "name": "financial_status",
              "value": "paid"
            }
          ]
        },
        "nodeCredentialType": "shopifyAccessTokenApi"
      },
      "credentials": {
        "shopifyAccessTokenApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "3802440d-c2cf-460a-ba19-2a36af2b2406",
      "name": "Split Out",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        2176,
        1232
      ],
      "parameters": {
        "options": {},
        "fieldToSplitOut": "orders"
      },
      "typeVersion": 1
    },
    {
      "id": "c9ce0ebd-c902-46dd-b2bc-043d1cac6fe5",
      "name": "Summarize",
      "type": "n8n-nodes-base.summarize",
      "position": [
        2592,
        1232
      ],
      "parameters": {
        "options": {},
        "fieldsToSummarize": {
          "values": [
            {
              "field": "current_price",
              "aggregation": "sum"
            }
          ]
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "c82deae3-c103-45f0-b26e-cf81f28ddba6",
      "name": "Append row in sheet",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        2848,
        1232
      ],
      "parameters": {
        "columns": {
          "value": {
            "Date": "={{ DateTime.now().setZone('Australia/Melbourne').minus({days: 1}).toISODate() }}\n",
            "Total Sales": "={{ $json.sum_current_price }}"
          },
          "schema": [
            {
              "id": "Date",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Date",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Total Sales",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Total Sales",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "row_number"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 1645443037,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1hsJbOC13FlZArNfNHOT4xOHXIGX64nbEDrvo3nBsxpc/edit#gid=1645443037",
          "cachedResultName": "shopify_daily_sales"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1hsJbOC13FlZArNfNHOT4xOHXIGX64nbEDrvo3nBsxpc",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1hsJbOC13FlZArNfNHOT4xOHXIGX64nbEDrvo3nBsxpc/edit?usp=drivesdk",
          "cachedResultName": "Stephanie TESTING - RE3 GREEN BOOK SEPTEMBER 2025"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "9545612a-7f5f-4a3a-9a73-2c6747703d7e",
      "name": "Edit Fields2",
      "type": "n8n-nodes-base.set",
      "position": [
        2384,
        1232
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "82ece415-95e2-4680-99fa-480318e5c1e7",
              "name": "current_price",
              "type": "number",
              "value": "={{ $json.current_total_price }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "4527bd24-8759-4b31-8f5c-5acf974cd19e",
      "name": "If",
      "type": "n8n-nodes-base.if",
      "position": [
        1968,
        1248
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "ac8c1680-1fe3-4e39-b2a5-9cb1ccd3be32",
              "operator": {
                "type": "array",
                "operation": "notEmpty",
                "singleValue": true
              },
              "leftValue": "={{ $json.orders }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "892cf81a-9924-42ca-bde8-4b1658410ab0",
      "name": "Append row in sheet1",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1984,
        1504
      ],
      "parameters": {
        "columns": {
          "value": {
            "Date": "={{ DateTime.now().setZone('Australia/Sydney').minus({days: 1}).toISODate() }}\n",
            "Total Sales": "=0"
          },
          "schema": [
            {
              "id": "Date",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Date",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Total Sales",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Total Sales",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "row_number"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 1645443037,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1hsJbOC13FlZArNfNHOT4xOHXIGX64nbEDrvo3nBsxpc/edit#gid=1645443037",
          "cachedResultName": "shopify_daily_sales"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1hsJbOC13FlZArNfNHOT4xOHXIGX64nbEDrvo3nBsxpc",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1hsJbOC13FlZArNfNHOT4xOHXIGX64nbEDrvo3nBsxpc/edit?usp=drivesdk",
          "cachedResultName": "Stephanie TESTING - RE3 GREEN BOOK SEPTEMBER 2025"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "29969853-91c3-4d7f-9da8-e5555cfb9204",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1520,
        992
      ],
      "parameters": {
        "color": 3,
        "width": 688,
        "content": "## Shopify Daily Sales report\n"
      },
      "typeVersion": 1
    },
    {
      "id": "b99a42ae-1583-4445-8c32-0dd7e22ff220",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        272,
        992
      ],
      "parameters": {
        "height": 208,
        "content": "## Tag filteration\n"
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "If": {
      "main": [
        [
          {
            "node": "Split Out",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Append row in sheet1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If2": {
      "main": [
        [
          {
            "node": "Edit Fields1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If3": {
      "main": [
        [
          {
            "node": "Append row in sheet2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code1": {
      "main": [
        [
          {
            "node": "If3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code5": {
      "main": [
        [
          {
            "node": "If2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Limit1": {
      "main": [
        [
          {
            "node": "Analyze image",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Out": {
      "main": [
        [
          {
            "node": "Edit Fields2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Summarize": {
      "main": [
        [
          {
            "node": "Append row in sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields": {
      "main": [
        [
          {
            "node": "Shopify Content Generator",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields1": {
      "main": [
        [
          {
            "node": "Update row in sheet1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields2": {
      "main": [
        [
          {
            "node": "Summarize",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Analyze image": {
      "main": [
        [
          {
            "node": "Edit Fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Error Trigger": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request1": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Simple Memory": {
      "ai_memory": [
        [
          {
            "node": "AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Every 5 Minutes": {
      "main": [
        [
          {
            "node": "Get row(s) in sheet2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Session Memory2": {
      "ai_memory": [
        [
          {
            "node": "Shopify Content Generator",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Get row(s) in sheet1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger1": {
      "main": [
        [
          {
            "node": "HTTP Request1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Append row in sheet2": {
      "main": [
        [
          {
            "node": "Limit2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get row(s) in sheet1": {
      "main": [
        [
          {
            "node": "Limit1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get row(s) in sheet2": {
      "main": [
        [
          {
            "node": "Fetch Shopify Products",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenRouter Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Shopify Content Generator",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Shopify Products": {
      "main": [
        [
          {
            "node": "Code1",
            "type": "main",
            "index": 0
          },
          {
            "node": "Code5",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenRouter Chat Model1": {
      "ai_languageModel": [
        [
          {
            "node": "Structured Output Parser",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "OpenRouter Chat Model2": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "Shopify Content Generator",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Shopify Content Generator": {
      "main": [
        [
          {
            "node": "Update row in sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Message a model in Perplexity": {
      "ai_tool": [
        [
          {
            "node": "Shopify Content Generator",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Message a model in Perplexity1": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Append row in sheet in Google Sheets": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "When clicking \u2018Execute workflow\u2019": {
      "main": [
        [
          {
            "node": "Get row(s) in sheet1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}