{
  "name": "DevOps ClickUp documentation backup",
  "nodes": [
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "109eed99-ef65-4bc3-b2f2-e54106436bfa",
              "leftValue": "={{ $json.fileContent }}",
              "rightValue": "",
              "operator": {
                "type": "string",
                "operation": "notEmpty",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        624,
        0
      ],
      "id": "fd2f531b-bbcb-4e10-9091-bada152f0953",
      "name": "is it not empty?"
    },
    {
      "parameters": {
        "operation": "toJson",
        "mode": "each",
        "options": {
          "format": false,
          "fileName": "={{ $json.fileName }}"
        }
      },
      "type": "n8n-nodes-base.convertToFile",
      "typeVersion": 1.1,
      "position": [
        928,
        -80
      ],
      "id": "70b2d900-0c0d-402c-82e2-440d129379bb",
      "name": "Files converted to binary"
    },
    {
      "parameters": {
        "resource": "object",
        "operation": "create",
        "bucketName": "clickup-test-backup",
        "objectName": "={{ $binary.data.fileName }}",
        "createData": {},
        "createQuery": {},
        "encryptionHeaders": {},
        "requestOptions": {}
      },
      "type": "n8n-nodes-base.googleCloudStorage",
      "typeVersion": 1,
      "position": [
        1136,
        -80
      ],
      "id": "012e9aab-36fd-4a61-a071-23abd4029829",
      "name": "Files saved individually as .md",
      "credentials": {
        "googleCloudStorageOAuth2Api": {
          "id": "AZ8XjlvLs6xmwH9j",
          "name": "Google Cloud Storage account"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "/**\n * Recursively flattens a ClickUp page and its sub-pages,\n * building a hierarchical file path.\n *\n * @param {any} page - A ClickUp page object.\n * @param {string} path - The parent path.\n * @returns {any[]} - A flat array of n8n output items.\n */\nfunction flattenPages(page, path) {\n  let allPages = [];\n  \n  // Sanitize the page name to be a safe file/folder name\n  // This replaces / \\ ? * : | \" < > etc. with a hyphen to prevent errors\n  const safeName = (page.name || \"untitled\").replace(/[\\/\\\\?%*:|\"<>]/g, '-');\n\n  // Create the full path for this file (e.g. \"Parent/Child\")\n  const fullPath = path + safeName;\n\n  // 1. Add the current page to our list\n  allPages.push({\n    json: {\n      // The Object Name for GCS, e.g., \"SecDevOps/City-Environment.md\"\n      fileName: fullPath + '.md', \n      \n      // The content for the file. \n      // We use a space \" \" if it's empty to prevent GCS upload errors.\n      fileContent: page.content || \"\",\n      \n      // Pass the bucket name along just in case you need it dynamically\n      bucketName: 'clickup-test-backup'\n    }\n  });\n\n  // 2. If this page has sub-pages, recursively flatten them\n  if (page.pages && page.pages.length > 0) {\n    for (const subPage of page.pages) {\n      // The new path for children is this page's path + a slash\n      allPages = allPages.concat(flattenPages(subPage, fullPath + '/'));\n    }\n  }\n\n  return allPages;\n}\n\n// --- MAIN EXECUTION ---\n// Get all items from the HTTP Request node\nconst allInputItems = $input.all();\nlet allFlattenedPages = [];\n\nfor (const item of allInputItems) {\n  // Start the flattening process for each top-level doc.\n  // We start with an empty path string \"\".\n  allFlattenedPages = allFlattenedPages.concat(flattenPages(item.json, \"\"));\n}\n\n// Return the final, complete, flat list of 466+ items.\nreturn allFlattenedPages;"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        416,
        0
      ],
      "id": "dcecb00f-3a03-47ca-99db-f17a4645d12f",
      "name": "Nested file structure flattened to one dimensional list"
    },
    {
      "parameters": {
        "url": "https://api.clickup.com/api/v3/workspaces/2496230/docs/2c5q6-69975/pages",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "clickUpApi",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "max_page_depth",
              "value": "-1"
            },
            {
              "name": "content_format",
              "value": "text/md"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.3,
      "position": [
        208,
        0
      ],
      "id": "d3002b74-24b3-47c7-abc9-c4ebf921c378",
      "name": "HTTP Request to specific wokspace where docs are located at",
      "credentials": {
        "clickUpApi": {
          "id": "dCeltvwDuFadeybB",
          "name": "ClickUp account"
        }
      }
    },
    {
      "parameters": {},
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        0,
        0
      ],
      "id": "1c51357c-65fb-4540-a81f-6957e7ece5be",
      "name": "Hit me"
    }
  ],
  "pinData": {},
  "connections": {
    "is it not empty?": {
      "main": [
        [
          {
            "node": "Files converted to binary",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Files converted to binary": {
      "main": [
        [
          {
            "node": "Files saved individually as .md",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Nested file structure flattened to one dimensional list": {
      "main": [
        [
          {
            "node": "is it not empty?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request to specific wokspace where docs are located at": {
      "main": [
        [
          {
            "node": "Nested file structure flattened to one dimensional list",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Hit me": {
      "main": [
        [
          {
            "node": "HTTP Request to specific wokspace where docs are located at",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "288af30c-beea-4b10-a8bd-e5a55e080c34",
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "4334e0234b716dac4655c945e80be4da0419e9739f0a0eb8de9a2a9b517a3c4a"
  },
  "id": "P54glaQDNI38zn7G",
  "tags": []
}