{
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "0f417d51-4cc1-470f-b9b9-39edc676022f",
      "name": "Analyze image",
      "type": "@n8n/n8n-nodes-langchain.googleGemini",
      "position": [
        -416,
        -240
      ],
      "parameters": {
        "text": "={{ $json.body.text }}\n\nname of the product: {{ $json.body.product_name }}\n\nin this product {{ $json.body.material_type }} fabric used.\n\nprovide output in json formate",
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "models/gemini-2.5-flash",
          "cachedResultName": "models/gemini-2.5-flash"
        },
        "options": {},
        "resource": "image",
        "inputType": "binary",
        "operation": "analyze",
        "binaryPropertyName": "file"
      },
      "credentials": {
        "googlePalmApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "6fffabf7-aeba-4a88-a49f-97dad25dae36",
      "name": "Code in JavaScript",
      "type": "n8n-nodes-base.code",
      "position": [
        -192,
        -240
      ],
      "parameters": {
        "jsCode": "// n8n Code node\nreturn items.map(item => {\n  let rawText = \"\";\n\n  try {\n    // Navigate safely into content.parts[0].text\n    rawText = item.json?.content?.parts?.[0]?.text || \"\";\n  } catch (e) {\n    rawText = \"\";\n  }\n\n  // Remove Markdown code block wrappers like ```json ... ```\n  rawText = rawText.replace(/```json/g, \"\").replace(/```/g, \"\").trim();\n\n  let parsed = {};\n  let output = {};\n\n  try {\n    // Try parsing JSON\n    parsed = JSON.parse(rawText);\n\n    // Copy everything dynamically\n    output = { ...parsed };\n\n  } catch (e) {\n    // If JSON parsing fails \u2192 treat as HTML\n    output.html = rawText.replace(/\\n/g, \"\"); // remove newline chars\n  }\n\n  return { json: output };\n});\n"
      },
      "typeVersion": 2
    },
    {
      "id": "96f7ece1-61a3-4bd0-ac12-48eb5465d7e1",
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "position": [
        -640,
        -144
      ],
      "parameters": {
        "path": "387b3de0-7931-478b-b7d0-9d12c013afc6",
        "options": {},
        "httpMethod": "POST",
        "responseMode": "responseNode"
      },
      "typeVersion": 2.1
    },
    {
      "id": "74d22a36-0277-4939-8ae7-296192fdb500",
      "name": "Respond to Webhook",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        32,
        -240
      ],
      "parameters": {
        "options": {},
        "respondWith": "allIncomingItems"
      },
      "typeVersion": 1.4
    },
    {
      "id": "e8b593f3-78be-443c-9155-ec451c655b8d",
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        928,
        -144
      ],
      "parameters": {
        "url": "https://dcbq8p-1b.myshopify.com/admin/api/2025-07/products.json",
        "method": "POST",
        "options": {
          "redirect": {
            "redirect": {}
          }
        },
        "jsonBody": "={\n  \"product\": {\n    \"title\": \"{{ $json.data[0].title }}\",\n    \"body_html\": {{ JSON.stringify($json.data[0].description) }},\n    \"vendor\": \"{{ $('Webhook').item.json.body.vendor }}\",\n    \"product_type\": \"{{ $('Webhook').item.json.body.product_type }}\",\n    \"tags\": \"{{ $json.data[0].tags }}\",\n    \"published\": true,\n    \"options\": {{ $('Webhook').item.json.body.options }},\n    \"variants\": {{ $('Webhook').item.json.body.variants }},\n    \"images\": [\n      {\n        \"src\": \"{{ $json.data[1].url }}\"\n      }\n    ],\n    \"seo\": {\n      \"title\": \"{{ $json.data[0].meta_title }}\",\n      \"description\": \"{{ $json.data[0].meta_description }}\"\n    }\n  }\n}",
        "sendBody": true,
        "sendHeaders": true,
        "specifyBody": "json",
        "headerParameters": {
          "parameters": [
            {
              "name": "X-Shopify-Access-Token"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "e7355758-b5bb-4c4d-b144-efbc9fbde39b",
      "name": "imgbb",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -416,
        -32
      ],
      "parameters": {
        "url": "https://api.imgbb.com/1/upload",
        "method": "POST",
        "options": {
          "redirect": {
            "redirect": {}
          }
        },
        "sendBody": true,
        "sendQuery": true,
        "contentType": "multipart-form-data",
        "authentication": "genericCredentialType",
        "bodyParameters": {
          "parameters": [
            {
              "name": "image",
              "parameterType": "formBinaryData",
              "inputDataFieldName": "file"
            }
          ]
        },
        "genericAuthType": "httpBasicAuth",
        "queryParameters": {
          "parameters": [
            {
              "name": "expiration",
              "value": "600"
            },
            {
              "name": "key",
              "value": "b0771673aa2a3df316ccc8dd96bb8562"
            }
          ]
        }
      },
      "credentials": {
        "httpBasicAuth": {
          "name": "<your credential>"
        },
        "httpBearerAuth": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "e706490c-ff25-4c03-b485-82a6de850e5b",
      "name": "Merge",
      "type": "n8n-nodes-base.merge",
      "position": [
        480,
        -144
      ],
      "parameters": {
        "mode": "combine",
        "options": {},
        "joinMode": "keepEverything",
        "fieldsToMatchString": "data"
      },
      "typeVersion": 3.2
    },
    {
      "id": "ab3ea824-b40b-406d-8d68-4e6411e7d283",
      "name": "Aggregate",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        704,
        -144
      ],
      "parameters": {
        "options": {},
        "fieldsToAggregate": {
          "fieldToAggregate": [
            {
              "fieldToAggregate": "data"
            }
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "id": "da7ab3f1-8566-42a6-9dce-64d7dd32bcd2",
      "name": "Edit Fields",
      "type": "n8n-nodes-base.set",
      "position": [
        256,
        -240
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "315e610b-5765-4e27-b12b-086295b06d63",
              "name": "data.title",
              "type": "string",
              "value": "={{ $json.title }}"
            },
            {
              "id": "a5ce2448-9876-42c4-932e-f159398c99d0",
              "name": "data.description",
              "type": "string",
              "value": "={{ $json.description }}"
            },
            {
              "id": "af5f4fcf-5795-4b5b-8778-5c53d1140acb",
              "name": "data.tags",
              "type": "string",
              "value": "={{ $json.tags }}"
            },
            {
              "id": "93db0c23-dc94-434f-b267-5ae30e8b6b7e",
              "name": "data.bullet_points",
              "type": "array",
              "value": "={{ $json.bullet_points }}"
            },
            {
              "id": "3cd64ab8-d31a-49bb-81bf-f63e93d2175a",
              "name": "data.alt_text",
              "type": "string",
              "value": "={{ $json.alt_text }}"
            },
            {
              "id": "cfbbbe35-e586-4cff-a84d-a18dfc0d1196",
              "name": "data.meta_title",
              "type": "string",
              "value": "={{ $json.meta_title }}"
            },
            {
              "id": "fc215a21-b411-4c84-b12d-6c3a5187f35e",
              "name": "data.meta_description",
              "type": "string",
              "value": "={{ $json.meta_description }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "37de4e93-133d-4473-b8c4-8644fe835981",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1232,
        -400
      ],
      "parameters": {
        "width": 448,
        "height": 528,
        "content": "## AI Product Listing on Shopify with Image Analysis\n\n### How it works\n1. Receives product details and an image via webhook.\n2. Uploads the product image to imgbb and simultaneously sends the image and product information to Google Gemini.\n3. Gemini analyzes the image and provided text to generate a product title, description, tags, and SEO metadata.\n4. The generated text and the uploaded image URL are combined.\n5. A new product is created in Shopify using all the generated and provided details.\n\n### Setup\n- [ ] Set up the Webhook URL in your source system to send product data and image.\n- [ ] Connect your Google Gemini (PaLM) account.\n- [ ] Connect your Shopify account with the necessary access token.\n- [ ] Ensure the incoming webhook data includes `product_name`, `material_type`, `file` (for the image), `vendor`, `product_type`, `options`, and `variants`."
      },
      "typeVersion": 1
    },
    {
      "id": "9d0f16b8-b75b-40fe-925f-dd3ebaf0aa9a",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -672,
        -304
      ],
      "parameters": {
        "color": 7,
        "width": 624,
        "height": 464,
        "content": "## 1. Get data and generate content and upload img to online storage\nsetup\nadd your imagebb api key"
      },
      "typeVersion": 1
    },
    {
      "id": "e5a11297-b090-483e-bd28-c555a191e9d3",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -32,
        -336
      ],
      "parameters": {
        "color": 7,
        "width": 432,
        "height": 336,
        "content": "## 2. provide generated data back to user"
      },
      "typeVersion": 1
    },
    {
      "id": "68ebb3ab-122c-4bed-9aa5-6dc1d1a73b1f",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        416,
        -256
      ],
      "parameters": {
        "color": 7,
        "width": 672,
        "height": 352,
        "content": "## 3. list item to shopify"
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "Merge": {
      "main": [
        [
          {
            "node": "Aggregate",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "imgbb": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Webhook": {
      "main": [
        [
          {
            "node": "Analyze image",
            "type": "main",
            "index": 0
          },
          {
            "node": "imgbb",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Aggregate": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request": {
      "main": [
        []
      ]
    },
    "Analyze image": {
      "main": [
        [
          {
            "node": "Code in JavaScript",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code in JavaScript": {
      "main": [
        [
          {
            "node": "Respond to Webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Respond to Webhook": {
      "main": [
        [
          {
            "node": "Edit Fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}