{
  "id": "6pqn4rVXEkn_2XS72k-8F",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Markdown to Confluence",
  "tags": [],
  "nodes": [
    {
      "id": "534a4954-1ab4-4a9e-a9b1-5a9b202221a4",
      "name": "File Created",
      "type": "n8n-nodes-base.googleDriveTrigger",
      "position": [
        0,
        0
      ],
      "parameters": {
        "event": "fileCreated",
        "options": {},
        "pollTimes": {
          "item": [
            {
              "mode": "everyHour"
            }
          ]
        },
        "triggerOn": "specificFolder",
        "folderToWatch": {}
      },
      "credentials": {},
      "typeVersion": 1
    },
    {
      "id": "b46bc406-fc97-48f2-b111-1bafabcd6f75",
      "name": "File Updated",
      "type": "n8n-nodes-base.googleDriveTrigger",
      "position": [
        0,
        176
      ],
      "parameters": {
        "event": "fileUpdated",
        "options": {},
        "pollTimes": {
          "item": [
            {
              "mode": "everyHour"
            }
          ]
        },
        "triggerOn": "specificFolder",
        "folderToWatch": {}
      },
      "credentials": {},
      "typeVersion": 1
    },
    {
      "id": "5638f976-16b6-4f3a-aa90-393aa435e0a8",
      "name": "Download file",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        416,
        -16
      ],
      "parameters": {
        "fileId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $json.id }}"
        },
        "options": {
          "googleFileConversion": {
            "conversion": {
              "docsToFormat": "=text/markdown"
            }
          }
        },
        "operation": "download"
      },
      "credentials": {},
      "typeVersion": 3
    },
    {
      "id": "56c2281c-b455-4860-85bf-984dea51356c",
      "name": "Markdown",
      "type": "n8n-nodes-base.markdown",
      "position": [
        784,
        -16
      ],
      "parameters": {
        "mode": "markdownToHtml",
        "options": {},
        "markdown": "={{ $json.data }}"
      },
      "typeVersion": 1
    },
    {
      "id": "033bf57f-2369-4e0e-8a93-7e04376a34f5",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        16,
        -560
      ],
      "parameters": {
        "width": 1088,
        "height": 480,
        "content": "# Markdown to Confluence Auto Loader\nThis workflow monitors a folder in a Google Drive for changes every hour. If an .md file is uploaded or edited, the workflow will take the file and create a Confluence page for it\n\n\n## Setup\n* Ensure you have an Oauth2 connection set up with access to the Google Drive API.\n* Point to the folder in 'File Created' / 'File Updated' triggers\n* Create a scoped API token for Confluence with the 'write:confluence-content' and 'write:content:confluence' scopes, then add it as a header auth for your HTTP request nodes\n* Add your Confluence Cloud ID to the URL in \"Create Confluence Page\", \"Get Page ID\", and \"Update Confluence Page\"\n\n## Instructions\nSave a .md file to the folder set in the triggers. This workflow will check every hour, convert the md file to HTML, and create a confluence page for it. If the md file is updated or changed in the folder, the workflow will check for a matching page in Confluence and update it."
      },
      "typeVersion": 1
    },
    {
      "id": "904b64b0-9e59-49e6-bbf9-30f28e3a3d08",
      "name": "If file ends in .md",
      "type": "n8n-nodes-base.if",
      "position": [
        208,
        0
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "or",
          "conditions": [
            {
              "id": "4d2e0237-4ae1-4aac-8bb4-5ed0f3475101",
              "operator": {
                "type": "string",
                "operation": "endsWith"
              },
              "leftValue": "={{ $json.originalFilename }}",
              "rightValue": ".md"
            },
            {
              "id": "8222976a-194d-4a5e-bbfd-8900c5481ee0",
              "operator": {
                "type": "string",
                "operation": "endsWith"
              },
              "leftValue": "={{ $json.name }}",
              "rightValue": ".md"
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "bade8969-6098-4aa6-9a3e-2d3238ab50f5",
      "name": "Convert file to markdown string",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        608,
        -16
      ],
      "parameters": {
        "options": {},
        "operation": "text"
      },
      "typeVersion": 1.1
    },
    {
      "id": "448f9908-f20c-4932-b248-3b5b60785ed8",
      "name": "If Trigger was File Created",
      "type": "n8n-nodes-base.if",
      "position": [
        992,
        -16
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "629adb89-9e63-466b-b999-2a91a5ec1579",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              },
              "leftValue": "={{ $('File Created').isExecuted }}",
              "rightValue": "True"
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "d3b4b515-fc4e-41b0-946e-8c8dbaa659da",
      "name": "Create Confluence Page",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1328,
        -32
      ],
      "parameters": {
        "url": "https://api.atlassian.com/ex/confluence/<CLOUD_ID>/wiki/api/v2/pages/",
        "method": "PUT",
        "options": {},
        "jsonBody": "={\n  \"spaceId\": \"65981\",\n  \"status\": \"current\",\n  \"title\": \"{{ $('If file ends in .md').item.json.name }}\",\n  \"body\": {\n    \"representation\": \"storage\",\n    \"value\": {{ JSON.stringify($json.data) }}\n  },\n  \"subtype\": \"live\"\n}",
        "sendBody": true,
        "sendHeaders": true,
        "specifyBody": "json",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "headerParameters": {
          "parameters": [
            {
              "name": "Accept",
              "value": "application/json"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        }
      },
      "credentials": {},
      "typeVersion": 4.3
    },
    {
      "id": "eeb14b03-e534-4526-bb26-6a57b16458d8",
      "name": "Update Confluence Page",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1328,
        176
      ],
      "parameters": {
        "url": "=https://api.atlassian.com/ex/confluence/<CLOUD_ID>/wiki/api/v2/pages/{{ $json.results[0].id }}",
        "method": "PUT",
        "options": {},
        "jsonBody": "={\n  \"id\": \"{{ $json.results[0].id }}\",\n  \"status\": \"current\",\n  \"title\": \"{{ $('If file ends in .md').item.json.name }}\",\n  \"body\": {\n    \"representation\": \"storage\",\n    \"value\": {{ JSON.stringify($('Markdown').item.json.data) }}\n  },\n  \"subtype\": \"live\",\n  \"version\": {\n    \"number\": {{ $json.results[0].version.number + 1 }},\n    \"message\": \"Markdown file updated in drive\"\n  }\n}",
        "sendBody": true,
        "sendHeaders": true,
        "specifyBody": "json",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "headerParameters": {
          "parameters": [
            {
              "name": "Accept",
              "value": "application/json"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        }
      },
      "credentials": {},
      "typeVersion": 4.3
    },
    {
      "id": "c1537cc7-8b92-4bf5-ae07-a02c2e5fbc9e",
      "name": "Get Page ID",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1152,
        176
      ],
      "parameters": {
        "url": "=https://api.atlassian.com/ex/confluence/<CLOUD_ID>/wiki/api/v2/pages?title={{ $('File Updated').item.json.name }}",
        "options": {},
        "sendHeaders": true,
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "headerParameters": {
          "parameters": [
            {
              "name": "Accept",
              "value": "application/json"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        }
      },
      "credentials": {},
      "typeVersion": 4.3
    }
  ],
  "active": true,
  "settings": {
    "callerPolicy": "workflowsFromSameOwner",
    "errorWorkflow": "gruh80gJzmCbk0l_wbQ4w",
    "timeSavedMode": "fixed",
    "availableInMCP": false,
    "executionOrder": "v1"
  },
  "versionId": "df653db9-237f-4c45-8d94-e5e58ccc288e",
  "connections": {
    "Markdown": {
      "main": [
        [
          {
            "node": "If Trigger was File Created",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Page ID": {
      "main": [
        [
          {
            "node": "Update Confluence Page",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "File Created": {
      "main": [
        [
          {
            "node": "If file ends in .md",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "File Updated": {
      "main": [
        [
          {
            "node": "If file ends in .md",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download file": {
      "main": [
        [
          {
            "node": "Convert file to markdown string",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If file ends in .md": {
      "main": [
        [
          {
            "node": "Download file",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If Trigger was File Created": {
      "main": [
        [
          {
            "node": "Create Confluence Page",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Get Page ID",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Convert file to markdown string": {
      "main": [
        [
          {
            "node": "Markdown",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}