{
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "upload-file-to-drive",
        "responseMode": "responseNode",
        "options": {}
      },
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        -3392,
        1760
      ],
      "id": "abe50d7f-13df-44bc-8023-55e29899ab33",
      "name": "Webhook - Upload File"
    },
    {
      "parameters": {
        "name": "={{ $('Set Variables6').item.json.fileName }}",
        "driveId": {
          "__rl": true,
          "value": "My Drive",
          "mode": "list",
          "cachedResultName": "My Drive",
          "cachedResultUrl": "https://drive.google.com/drive/my-drive"
        },
        "folderId": {
          "__rl": true,
          "value": "={{ $('Set Variables6').item.json.folderId }}",
          "mode": "id"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [
        -2768,
        1776
      ],
      "id": "6b256608-7f70-42ea-a006-28e8d1692417",
      "name": "Upload to Google Drive",
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "continueOnFail": true,
      "onError": "continueErrorOutput"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "1",
              "name": "success",
              "value": "=true",
              "type": "boolean"
            },
            {
              "id": "2",
              "name": "drive_file_id",
              "value": "={{ $json.id }}",
              "type": "string"
            },
            {
              "id": "3",
              "name": "drive_file_url",
              "value": "=https://drive.google.com/file/d/{{ $json.id }}/view",
              "type": "string"
            },
            {
              "id": "4",
              "name": "file_name",
              "value": "={{ $json.name }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -2544,
        1760
      ],
      "id": "a315d382-f676-4d4a-9dd4-7d2df7d8755c",
      "name": "Format Response"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "1",
              "name": "success",
              "value": "=false",
              "type": "boolean"
            },
            {
              "id": "2",
              "name": "error",
              "value": "={{ $json.error?.message || $json.message || 'Error uploading file to Google Drive' }}",
              "type": "string"
            },
            {
              "id": "3",
              "name": "error_details",
              "value": "={{ $json.error?.description || $json.description || 'Unknown error' }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -2544,
        1952
      ],
      "id": "61cdfb1f-ba4f-4693-9891-8c1d58c507a1",
      "name": "Format Error"
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ $json }}",
        "options": {
          "responseCode": 500
        }
      },
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [
        -2288,
        1952
      ],
      "id": "e4c7506e-9370-47fc-bae4-c2c8b7db5fa8",
      "name": "Respond Error"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "1",
              "name": "fileName",
              "value": "={{ $json.body.fileName }}",
              "type": "string"
            },
            {
              "id": "2",
              "name": "folderId",
              "value": "={{ $json.body.folderId }}",
              "type": "string"
            },
            {
              "id": "3",
              "name": "fileContent",
              "value": "={{ $json.body.fileContent }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -3168,
        1760
      ],
      "id": "144dc59d-5238-490d-8672-0d856e54900e",
      "name": "Set Variables6"
    },
    {
      "parameters": {
        "options": {
          "fileName": "={{ $json.fileName }}"
        }
      },
      "type": "n8n-nodes-base.convertToFile",
      "typeVersion": 1.1,
      "position": [
        -2960,
        1760
      ],
      "id": "e0ef6492-bc01-4e7e-a48d-3916b03a6c82",
      "name": "Convert to File"
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ $json }}",
        "options": {}
      },
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [
        -2288,
        1760
      ],
      "id": "6ffcb655-bf2b-4017-b6f7-41045d94405e",
      "name": "Respond Success6"
    }
  ],
  "connections": {
    "Webhook - Upload File": {
      "main": [
        [
          {
            "node": "Set Variables6",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upload to Google Drive": {
      "main": [
        [
          {
            "node": "Format Response",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Format Error",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format Response": {
      "main": [
        [
          {
            "node": "Respond Success6",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format Error": {
      "main": [
        [
          {
            "node": "Respond Error",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Variables6": {
      "main": [
        [
          {
            "node": "Convert to File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Convert to File": {
      "main": [
        [
          {
            "node": "Upload to Google Drive",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "meta": {
    "templateCredsSetupCompleted": true
  }
}