{
  "nodes": [
    {
      "id": "44ff0291-8949-493a-8dbb-201454ab1f92",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        128,
        48
      ],
      "parameters": {
        "width": 912,
        "height": 208,
        "content": "# \u26a0\ufe0f Create your Streamline credential first\n\nEnter your Shop ID when creating the credential. Once saved, select that credential from the dropdown \u2014 just like any standard n8n node. You can delete this sticky once complete."
      },
      "typeVersion": 1
    },
    {
      "id": "b8d4add8-5868-4156-b68b-17c2e3e76c06",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        128,
        256
      ],
      "parameters": {
        "color": 4,
        "width": 912,
        "height": 432,
        "content": "## \ud83e\udde9 Email Daily Shopify Order Report - Streamline Connector\n### A simple n8n workflow that fetches all orders from your Shopify store using Streamline Connector, then prepares and sends a daily order report.\n---\n\n\n\n\n\n\n\n\n\n\n\n\n---\n## \u2699\ufe0f How to Use\n1. Connect your credentials.\n2. Change the \"to\" in the Gmail node to your email.\n3. Save and turn on your workflow.\n4. Click run! This workflow will run every night at midnight."
      },
      "typeVersion": 1
    },
    {
      "id": "b7082b51-1e6b-4194-8086-e400401317c4",
      "name": "split_orders",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        784,
        368
      ],
      "parameters": {
        "options": {},
        "fieldToSplitOut": "data"
      },
      "typeVersion": 1
    },
    {
      "id": "338515e8-2f5c-430f-a96a-5a15d5b42a90",
      "name": "last_24_hours",
      "type": "n8n-nodes-base.filter",
      "position": [
        1136,
        368
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "8efda825-22b2-4754-b994-5cd7053cf79e",
              "operator": {
                "type": "dateTime",
                "operation": "after"
              },
              "leftValue": "={{ $json.metadata.date }}",
              "rightValue": "={{ $now.minus(24, 'hours') }}"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "adc38812-1d54-4a21-901a-bd142150a36e",
      "name": "prepare_email",
      "type": "n8n-nodes-base.code",
      "position": [
        1392,
        368
      ],
      "parameters": {
        "jsCode": "// Normalize incoming data into an array of order objects\n\nlet orders = [];\n\n// Case 1: Each n8n item is one order\nif (items.length > 1) {\n  orders = items.map(i => i.json);\n}\n\n// Case 2: A single item contains an array inside json\nelse if (Array.isArray(items[0].json)) {\n  orders = items[0].json;\n}\n\n// Case 3: Single item with a single order object\nelse {\n  orders = [items[0].json];\n}\n\n// Minimal CSS for readability\nconst styles = `\n  <style>\n    body { font-family: Arial, sans-serif; font-size: 14px; color: #333; }\n    h1 { font-size: 20px; margin-bottom: 10px; }\n    .order-container { \n      border: 1px solid #ddd; \n      padding: 12px; \n      margin-bottom: 15px; \n      border-radius: 4px; \n    }\n    .order-header { font-weight: bold; margin-bottom: 6px; }\n    .order-image { max-width: 120px; border: 1px solid #eee; margin-top: 8px; }\n    a { color: #0066cc; }\n  </style>\n`;\n\nfunction formatDate(iso) {\n  try {\n    return new Date(iso).toLocaleString();\n  } catch {\n    return iso;\n  }\n}\n\n// Build HTML per order\nconst ordersHTML = orders\n  .map(order => {\n    const m = order.metadata || {};\n\n    return `\n      <div class=\"order-container\">\n        <div class=\"order-header\">Order #${m.id || \"Unknown\"}</div>\n\n        <div><strong>Status:</strong> ${m.order_status || \"Unknown\"}</div>\n        <div><strong>Total Price:</strong> $${m.total_price || \"0.00\"}</div>\n        <div><strong>Date:</strong> ${formatDate(m.date)}</div>\n        <div><strong>Fulfillment:</strong> ${m.fulfillment_status || \"Not fulfilled\"}</div>\n        <div><strong>Tracking:</strong> ${m.trackingUrls || \"N/A\"}</div>\n        \n        <div><strong>Order Status URL:</strong> \n          <a href=\"${m.order_status_url}\" target=\"_blank\">View Order</a>\n        </div>\n\n        ${m.product_image ? `<img class=\"order-image\" src=\"${m.product_image}\" />` : \"\"}\n      </div>\n    `;\n  })\n  .join(\"\\n\");\n\n// Final HTML\nconst html = `\n<!DOCTYPE html>\n<html>\n<head>${styles}</head>\n<body>\n  <h1>Daily Order Report</h1>\n  ${ordersHTML}\n</body>\n</html>\n`;\n\nreturn [\n  {\n    json: { html }\n  }\n];\n"
      },
      "typeVersion": 2
    },
    {
      "id": "1ab38b6f-2392-4143-8906-29455cde1ce3",
      "name": "send_email",
      "type": "n8n-nodes-base.gmail",
      "position": [
        1600,
        368
      ],
      "parameters": {
        "message": "={{ $json.html }}",
        "options": {
          "appendAttribution": false
        },
        "subject": "Daily Order Report"
      },
      "notesInFlow": true,
      "typeVersion": 2.1
    },
    {
      "id": "b107a1a6-93e8-41bf-a99e-7a445b67cc4a",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1056,
        288
      ],
      "parameters": {
        "color": 6,
        "width": 832,
        "height": 288,
        "content": "## \ud83d\ude80 Check your email for report!"
      },
      "typeVersion": 1
    },
    {
      "id": "3d337e0e-120d-484f-89f3-206d53f17d27",
      "name": "every_24h",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -80,
        320
      ],
      "parameters": {
        "rule": {
          "interval": [
            {}
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "9b03d732-becc-4506-890a-8d0e6cf5bed1",
      "name": "daily_order_report",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        -80,
        464
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "59f3b9c4-6d16-4b7a-be7b-e0b449965bf6",
      "name": "Streamline Connector1",
      "type": "n8n-nodes-streamline.streamline",
      "position": [
        528,
        368
      ],
      "parameters": {
        "resource": "orderActions",
        "operation": "getMany",
        "requestOptions": {}
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "every_24h": {
      "main": [
        [
          {
            "node": "Streamline Connector1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "split_orders": {
      "main": [
        [
          {
            "node": "last_24_hours",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "last_24_hours": {
      "main": [
        [
          {
            "node": "prepare_email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "prepare_email": {
      "main": [
        [
          {
            "node": "send_email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "daily_order_report": {
      "main": [
        [
          {
            "node": "Streamline Connector1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Streamline Connector1": {
      "main": [
        [
          {
            "node": "split_orders",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}