{
  "name": "Gmail Success Cases Export",
  "nodes": [
    {
      "parameters": {
        "pollTimes": {
          "item": [
            {
              "mode": "everyHour"
            }
          ]
        },
        "filters": {
          "labelIds": [
            "Label_XXXXXXXXXX"
          ]
        },
        "options": {
          "maxResults": 50
        }
      },
      "id": "gmail-trigger",
      "name": "Gmail Trigger - Success Cases",
      "type": "n8n-nodes-base.gmailTrigger",
      "typeVersion": 1,
      "position": [
        240,
        300
      ],
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "// Format email data for storage\nconst email = $input.item.json;\n\nconst formatted = {\n  messageId: email.id || '',\n  threadId: email.threadId || '',\n  from: email.From || email.from || '',\n  to: email.To || email.to || '',\n  subject: email.Subject || email.subject || '',\n  date: email.Date || email.date || new Date().toISOString(),\n  snippet: email.snippet || '',\n  body: email.text || email.textPlain || email.html || '',\n  labels: (email.labelIds || []).join(', '),\n  exportedAt: new Date().toISOString()\n};\n\nreturn { json: formatted };"
      },
      "id": "format-email",
      "name": "Format Email Data",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        460,
        300
      ]
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "13iOvpUd6OjZPgMeFKL42RlPk326JCLNzT8tyEM-SY8I",
          "mode": "id"
        },
        "sheetName": {
          "__rl": true,
          "value": "Success Cases",
          "mode": "name"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "Message ID": "={{ $json.messageId }}",
            "Thread ID": "={{ $json.threadId }}",
            "From": "={{ $json.from }}",
            "To": "={{ $json.to }}",
            "Subject": "={{ $json.subject }}",
            "Date": "={{ $json.date }}",
            "Snippet": "={{ $json.snippet }}",
            "Body": "={{ $json.body }}",
            "Labels": "={{ $json.labels }}",
            "Exported At": "={{ $json.exportedAt }}"
          }
        },
        "options": {}
      },
      "id": "google-sheets",
      "name": "Save to Google Sheets",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        680,
        300
      ],
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "content": "## Gmail Success Cases Export\n\n### \u8a2d\u5b9a\u624b\u9806\n\n1. **Gmail\u3067\u30e9\u30d9\u30eb\u4f5c\u6210**\n   - \u300csuccess-cases\u300d\u30e9\u30d9\u30eb\u3092\u4f5c\u6210\n   - \u6210\u529f\u4e8b\u4f8b\u306e\u30e1\u30fc\u30eb\u306b\u3053\u306e\u30e9\u30d9\u30eb\u3092\u4ed8\u3051\u308b\n\n2. **\u30e9\u30d9\u30ebID\u3092\u53d6\u5f97**\n   - Gmail Trigger\u30ce\u30fc\u30c9\u3092\u30af\u30ea\u30c3\u30af\n   - \u300cParameters\u300d\u2192\u300cFilters\u300d\u2192\u300cLabel IDs\u300d\n   - \u300cFetch Labels\u300d\u3067\u53d6\u5f97\u53ef\u80fd\n\n3. **Google Sheets\u306e\u6e96\u5099**\n   - \u300cSuccess Cases\u300d\u30b7\u30fc\u30c8\u3092\u4f5c\u6210\n   - \u30d8\u30c3\u30c0\u30fc\u884c: Message ID, Thread ID, From, To, Subject, Date, Snippet, Body, Labels, Exported At\n\n4. **\u8a8d\u8a3c\u8a2d\u5b9a**\n   - Gmail\u8a8d\u8a3c\n   - Google Sheets\u8a8d\u8a3c",
        "height": 400,
        "width": 350
      },
      "id": "sticky-note",
      "name": "Setup Instructions",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        240,
        -100
      ]
    }
  ],
  "connections": {
    "Gmail Trigger - Success Cases": {
      "main": [
        [
          {
            "node": "Format Email Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format Email Data": {
      "main": [
        [
          {
            "node": "Save to Google Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  }
}