{
  "name": "Sync Shopify Orders to Google Sheets",
  "nodes": [
    {
      "parameters": {
        "topic": "orders/create"
      },
      "id": "shopify-trigger",
      "name": "Shopify Trigger",
      "type": "n8n-nodes-base.shopifyTrigger",
      "typeVersion": 1,
      "position": [0, 0],
      "webhookId": "shopify-orders-create",
      "credentials": {
        "shopifyAccessTokenApi": {
          "id": "{{SHOPIFY_CREDENTIAL_ID}}",
          "name": "Shopify Access Token"
        }
      }
    },
    {
      "parameters": {
        "mode": "manual",
        "duplicateItem": false,
        "assignments": {
          "assignments": [
            {
              "id": "field-order-number",
              "name": "Order #",
              "value": "={{ $json.name }}",
              "type": "string"
            },
            {
              "id": "field-date",
              "name": "Date",
              "value": "={{ $json.created_at }}",
              "type": "string"
            },
            {
              "id": "field-customer",
              "name": "Customer",
              "value": "={{ $json.customer.first_name }} {{ $json.customer.last_name }}",
              "type": "string"
            },
            {
              "id": "field-email",
              "name": "Email",
              "value": "={{ $json.email }}",
              "type": "string"
            },
            {
              "id": "field-items",
              "name": "Items",
              "value": "={{ $json.line_items.map(i => i.title + ' x' + i.quantity).join(', ') }}",
              "type": "string"
            },
            {
              "id": "field-quantity",
              "name": "Quantity",
              "value": "={{ $json.line_items.reduce((sum, i) => sum + i.quantity, 0) }}",
              "type": "number"
            },
            {
              "id": "field-total",
              "name": "Total",
              "value": "={{ $json.total_price }}",
              "type": "string"
            },
            {
              "id": "field-currency",
              "name": "Currency",
              "value": "={{ $json.currency }}",
              "type": "string"
            },
            {
              "id": "field-shipping-address",
              "name": "Shipping Address",
              "value": "={{ $json.shipping_address?.address1 }}, {{ $json.shipping_address?.city }}",
              "type": "string"
            },
            {
              "id": "field-status",
              "name": "Status",
              "value": "={{ $json.financial_status }}",
              "type": "string"
            }
          ]
        },
        "includeOtherFields": false
      },
      "id": "set-fields",
      "name": "Extract Order Fields",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [300, 0]
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "{{GOOGLE_SHEET_ID}}"
        },
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "Sheet1"
        },
        "columns": {
          "mappingMode": "autoMapInputData",
          "value": {}
        },
        "options": {}
      },
      "id": "google-sheets-append",
      "name": "Append to Google Sheets",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [600, 0],
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "{{GOOGLE_SHEETS_CREDENTIAL_ID}}",
          "name": "Google Sheets OAuth2"
        }
      }
    }
  ],
  "connections": {
    "Shopify Trigger": {
      "main": [
        [
          {
            "node": "Extract Order Fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Order Fields": {
      "main": [
        [
          {
            "node": "Append to Google Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": null,
  "tags": [],
  "triggerCount": 1,
  "active": false
}
