{
  "name": "SinoDossier — Notion AI Product Research Radar & Shopify Auto-Drafter",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "ecom-product-radar",
        "options": {}
      },
      "id": "node-webhook-trigger",
      "name": "1. Receive Product / Ad URL",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [200, 300],
      "webhookId": "ecom-product-radar-trigger"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.apify.com/v2/acts/apify~e-commerce-scraping-tool/run-sync-get-dataset-items?token=YOUR_APIFY_API_TOKEN",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"detailsUrls\": [\n    { \"url\": \"{{ $json.body.product_url }}\" }\n  ],\n  \"additionalProperties\": true,\n  \"maxReviews\": 50\n}",
        "options": {
          "timeout": 60000
        }
      },
      "id": "node-apify-scrape",
      "name": "2. Apify Scrape Product & Reviews",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [460, 300]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.openai.com/v1/chat/completions",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer YOUR_OPENAI_API_KEY"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"model\": \"gpt-4o-mini\",\n  \"response_format\": { \"type\": \"json_object\" },\n  \"messages\": [\n    {\n      \"role\": \"system\",\n      \"content\": \"You are the SinoDossier ecom-product-radar Skill. Evaluate the product across 5 criteria (20 pts each): Wow Factor, Margin Potential, Review Gap, Evergreen Demand, Shipping Friendliness. Return strict JSON with keys: product_name, category, viability_score (0-100 number), verdict (LAUNCH NOW | TEST WITH ANGLE | SKIP), est_retail_price (string like $49.00), top_pain_points (string), differentiation_angle (string), shopify_title (string), shopify_body_html (string with 3 bullets + 3 FAQs), ad_hooks (array of 3 strings).\"\n    },\n    {\n      \"role\": \"user\",\n      \"content\": \"Analyze this scraped ecommerce product & customer review data:\\n{{ JSON.stringify($json).slice(0, 12000) }}\"\n    }\n  ]\n}",
        "options": {}
      },
      "id": "node-ai-scorer",
      "name": "3. AI Product Radar Skill (Score & Copy)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [720, 300]
    },
    {
      "parameters": {
        "jsCode": "const raw = $input.first().json.choices?.[0]?.message?.content || '{}';\nconst parsed = JSON.parse(raw);\nconst sourceUrl = $('1. Receive Product / Ad URL').first().json.body?.product_url || '';\n\nreturn [\n  {\n    json: {\n      product_name: parsed.product_name || 'Untitled Product',\n      category: parsed.category || 'General',\n      viability_score: Number(parsed.viability_score || 0),\n      verdict: parsed.verdict || 'TEST WITH ANGLE',\n      est_retail_price: parsed.est_retail_price || '$39.90',\n      top_pain_points: parsed.top_pain_points || '',\n      differentiation_angle: parsed.differentiation_angle || '',\n      shopify_title: parsed.shopify_title || parsed.product_name || 'New Draft Product',\n      shopify_body_html: parsed.shopify_body_html || '',\n      ad_hooks: Array.isArray(parsed.ad_hooks) ? parsed.ad_hooks.join('\\n---\\n') : '',\n      source_url: sourceUrl\n    }\n  }\n];"
      },
      "id": "node-parse-json",
      "name": "4. Parse AI Score JSON",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [980, 300]
    },
    {
      "parameters": {
        "resource": "databasePage",
        "databaseId": "YOUR_NOTION_DATABASE_ID",
        "title": "={{ $json.product_name }}",
        "propertiesUi": {
          "propertyValues": [
            {
              "key": "Score|number",
              "numberValue": "={{ $json.viability_score }}"
            },
            {
              "key": "Verdict|select",
              "selectValue": "={{ $json.verdict }}"
            },
            {
              "key": "Est Retail Price|rich_text",
              "textContent": "={{ $json.est_retail_price }}"
            },
            {
              "key": "Top 3 Competitor Complaints|rich_text",
              "textContent": "={{ $json.top_pain_points }}"
            },
            {
              "key": "Shopify Draft Copy|rich_text",
              "textContent": "={{ $json.shopify_title + '\\n\\n' + $json.ad_hooks }}"
            },
            {
              "key": "Source Ad URL|url",
              "urlValue": "={{ $json.source_url }}"
            },
            {
              "key": "Status|select",
              "selectValue": "={{ $json.viability_score >= 80 ? 'Approved' : 'Needs Review' }}"
            }
          ]
        }
      },
      "id": "node-notion-create",
      "name": "5. Save to Notion Ecom Radar DB",
      "type": "n8n-nodes-base.notion",
      "typeVersion": 2.2,
      "position": [1240, 300]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict"
          },
          "conditions": [
            {
              "id": "score-gate-80",
              "leftValue": "={{ $('4. Parse AI Score JSON').first().json.viability_score }}",
              "rightValue": 80,
              "operator": {
                "type": "number",
                "operation": "gte"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "node-if-winner",
      "name": "6. Score >= 80? (Auto-Draft Gate)",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [1500, 300]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://YOUR_STORE.myshopify.com/admin/api/2025-01/products.json",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "X-Shopify-Access-Token",
              "value": "YOUR_SHOPIFY_ADMIN_ACCESS_TOKEN"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"product\": {\n    \"title\": \"{{ $('4. Parse AI Score JSON').first().json.shopify_title }}\",\n    \"body_html\": {{ JSON.stringify($('4. Parse AI Score JSON').first().json.shopify_body_html) }},\n    \"product_type\": \"{{ $('4. Parse AI Score JSON').first().json.category }}\",\n    \"status\": \"draft\",\n    \"tags\": \"ai-radar, score-{{ $('4. Parse AI Score JSON').first().json.viability_score }}\"\n  }\n}",
        "options": {}
      },
      "id": "node-shopify-draft",
      "name": "7. Create Shopify Product Draft",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [1780, 220]
    }
  ],
  "connections": {
    "1. Receive Product / Ad URL": {
      "main": [
        [
          {
            "node": "2. Apify Scrape Product & Reviews",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "2. Apify Scrape Product & Reviews": {
      "main": [
        [
          {
            "node": "3. AI Product Radar Skill (Score & Copy)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "3. AI Product Radar Skill (Score & Copy)": {
      "main": [
        [
          {
            "node": "4. Parse AI Score JSON",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "4. Parse AI Score JSON": {
      "main": [
        [
          {
            "node": "5. Save to Notion Ecom Radar DB",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "5. Save to Notion Ecom Radar DB": {
      "main": [
        [
          {
            "node": "6. Score >= 80? (Auto-Draft Gate)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "6. Score >= 80? (Auto-Draft Gate)": {
      "main": [
        [
          {
            "node": "7. Create Shopify Product Draft",
            "type": "main",
            "index": 0
          }
        ],
        []
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {},
  "tags": [
    {
      "name": "SinoDossier"
    },
    {
      "name": "Ecommerce"
    }
  ]
}
