{
  "name": "QRlytics vCard QR Generator",
  "nodes": [
    {
      "parameters": {
        "formTitle": "Generate vCard QR Codes",
        "formDescription": "Create unique trackable QR codes with contact information for business cards",
        "formFields": {
          "values": [
            {
              "fieldLabel": "Number of Cards",
              "fieldType": "number",
              "placeholder": "e.g., 500 (one per business card)",
              "requiredField": true
            },
            {
              "fieldLabel": "Card Prefix",
              "placeholder": "e.g., BIZCARD",
              "requiredField": true
            },
            {
              "fieldLabel": "Full Name",
              "placeholder": "e.g., John Smith",
              "requiredField": true
            },
            {
              "fieldLabel": "Company",
              "placeholder": "e.g., Acme Corp",
              "requiredField": false
            },
            {
              "fieldLabel": "Phone",
              "placeholder": "e.g., +420 123 456 789",
              "requiredField": false
            },
            {
              "fieldLabel": "Email",
              "placeholder": "e.g., john@acme.com",
              "requiredField": false
            },
            {
              "fieldLabel": "Website",
              "placeholder": "e.g., https://acme.com",
              "requiredField": false
            },
            {
              "fieldLabel": "Address",
              "placeholder": "e.g., 123 Main St, Prague",
              "requiredField": false
            },
            {
              "fieldLabel": "Google Drive Folder ID",
              "placeholder": "Folder ID from Google Drive",
              "requiredField": true
            }
          ]
        },
        "options": {}
      },
      "id": "d1e2f3a4-card-form-0001-000000000001",
      "name": "vCard QR Form",
      "type": "n8n-nodes-base.formTrigger",
      "typeVersion": 2.2,
      "position": [288, -240]
    },
    {
      "parameters": {
        "jsCode": "const form = $input.first().json;\nconst count = parseInt(form['Number of Cards']) || 10;\nconst prefix = form['Card Prefix'] || 'CARD';\nconst fullName = form['Full Name'] || '';\nconst company = form['Company'] || '';\nconst phone = form['Phone'] || '';\nconst email = form['Email'] || '';\nconst website = form['Website'] || '';\nconst address = form['Address'] || '';\nconst folderId = form['Google Drive Folder ID'];\n\n// Parse name into first/last\nconst nameParts = fullName.trim().split(/\\s+/);\nconst firstName = nameParts[0] || '';\nconst lastName = nameParts.slice(1).join(' ') || '';\n\n// Build vCard string\nlet vcard = 'BEGIN:VCARD\\nVERSION:3.0';\nvcard += `\\nN:${lastName};${firstName};;;`;\nvcard += `\\nFN:${fullName}`;\nif (company) vcard += `\\nORG:${company}`;\nif (phone) vcard += `\\nTEL:${phone}`;\nif (email) vcard += `\\nEMAIL:${email}`;\nif (website) vcard += `\\nURL:${website}`;\nif (address) vcard += `\\nADR:;;${address}`;\nvcard += '\\nEND:VCARD';\n\nconst items = [];\nfor (let i = 1; i <= count; i++) {\n  const itemId = `${prefix}-${String(i).padStart(4, '0')}`;\n  items.push({\n    index: i,\n    item_id: itemId,\n    content: vcard,\n    folder_id: folderId,\n    prefix: prefix,\n    total_count: count\n  });\n}\n\nreturn items.map(item => ({ json: item }));"
      },
      "id": "d1e2f3a4-card-code-0001-000000000002",
      "name": "Generate QR Array",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [512, -240]
    },
    {
      "parameters": {
        "options": {}
      },
      "id": "d1e2f3a4-card-loop-0001-000000000003",
      "name": "Loop Over Items",
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 3,
      "position": [736, -240]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://qrlytics.eu/api/v1/qr",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "name",
              "value": "={{ $json.item_id }}"
            },
            {
              "name": "type",
              "value": "vcard"
            },
            {
              "name": "content",
              "value": "={{ $json.content }}"
            }
          ]
        },
        "options": {}
      },
      "id": "d1e2f3a4-card-api-0001-000000000004",
      "name": "Create QR via API",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.3,
      "position": [1136, -32],
      "credentials": {
        "httpHeaderAuth": {
          "id": "",
          "name": ""
        }
      }
    },
    {
      "parameters": {
        "jsCode": "const qrResponse = $('Create QR via API').item.json;\nconst itemData = $('Loop Over Items').item.json;\n\nconst base64DataUrl = qrResponse.qr_image_url;\nif (!base64DataUrl) {\n  throw new Error('No qr_image_url in API response. Keys: ' + Object.keys(qrResponse).join(', '));\n}\n\nconst base64Data = base64DataUrl.replace(/^data:image\\/\\w+;base64,/, '');\nconst buffer = Buffer.from(base64Data, 'base64');\nconst fileName = `${itemData.item_id}.png`;\n\nconst binaryData = await this.helpers.prepareBinaryData(\n  buffer,\n  fileName,\n  'image/png'\n);\n\nreturn [{\n  json: {\n    item_id: itemData.item_id,\n    folder_id: itemData.folder_id,\n    prefix: itemData.prefix,\n    short_url: qrResponse.short_url,\n    qr_id: qrResponse.id\n  },\n  binary: {\n    data: binaryData\n  }\n}];"
      },
      "id": "d1e2f3a4-card-conv-0001-000000000005",
      "name": "Convert Base64 to Image",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [1344, -32]
    },
    {
      "parameters": {
        "name": "={{ $json.item_id }}.png",
        "folderId": {
          "__rl": true,
          "value": "={{ $json.folder_id }}",
          "mode": "id"
        },
        "options": {}
      },
      "id": "d1e2f3a4-card-driv-0001-000000000006",
      "name": "Upload to Google Drive",
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [1552, -32],
      "credentials": {
        "googleDriveOAuth2Api": {
          "id": "",
          "name": ""
        }
      }
    },
    {
      "parameters": {
        "jsCode": "const items = $input.all();\nconst first = items[0]?.json || {};\n\nreturn [{\n  json: {\n    success: true,\n    message: `Successfully generated ${items.length} vCard QR codes`,\n    prefix: first.prefix || 'CARD',\n    total_created: items.length,\n    folder_id: first.folder_id\n  }\n}];"
      },
      "id": "d1e2f3a4-card-summ-0001-000000000007",
      "name": "Summarize Results",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [1136, -224]
    },
    {
      "parameters": {
        "sendTo": "",
        "subject": "vCard QR Codes Generated",
        "message": "={{ $json.message }}",
        "options": {}
      },
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.2,
      "position": [1344, -224],
      "id": "d1e2f3a4-card-mail-0001-000000000008",
      "name": "Send Notification",
      "credentials": {
        "gmailOAuth2": {
          "id": "",
          "name": ""
        }
      }
    }
  ],
  "connections": {
    "vCard QR Form": {
      "main": [
        [
          {
            "node": "Generate QR Array",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate QR Array": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items": {
      "main": [
        [
          {
            "node": "Summarize Results",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Create QR via API",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create QR via API": {
      "main": [
        [
          {
            "node": "Convert Base64 to Image",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Convert Base64 to Image": {
      "main": [
        [
          {
            "node": "Upload to Google Drive",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upload to Google Drive": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Summarize Results": {
      "main": [
        [
          {
            "node": "Send Notification",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1",
    "timezone": "Europe/Prague"
  },
  "meta": {
    "templateCredsSetupCompleted": false
  },
  "tags": [
    "QRlytics",
    "vCard",
    "Business Card",
    "API"
  ]
}
