{
  "name": "Publish a polished Markdown PDF",
  "active": false,
  "nodes": [
    {
      "parameters": {},
      "id": "b1b4835e-9a2d-45ef-8d97-7514b0568fd5",
      "name": "Run workflow",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [-900, 120]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "3a3fbd74-084b-4ae5-828f-b7c4457e54c1",
              "name": "taskId",
              "type": "string",
              "value": "consulting-proposal"
            },
            {
              "id": "f4f3a6bd-3396-4f90-ac8f-8daa05a1c0e5",
              "name": "title",
              "type": "string",
              "value": "Northstar discovery proposal"
            },
            {
              "id": "4c37e514-75f9-44a7-a1a0-b6d826248a66",
              "name": "markdown",
              "type": "string",
              "value": "# Northstar Discovery Proposal\n\n## Outcome\n\nA focused discovery sprint that turns an uncertain product brief into a decision-ready roadmap.\n\n## Scope\n\n| Workstream | Deliverable |\n| --- | --- |\n| Research | Stakeholder and customer synthesis |\n| Strategy | Prioritized opportunity map |\n| Planning | 90-day delivery roadmap |\n\n## Investment\n\n**CAD 8,400** fixed fee, delivered over three weeks.\n\n## Next step\n\nApprove the scope and schedule the kickoff workshop."
            },
            {
              "id": "19670662-754a-43ce-9804-a0b63951e54f",
              "name": "templateId",
              "type": "string",
              "value": "proposal-consulting"
            },
            {
              "id": "a75d8684-071f-481c-a42b-1b657171b3b0",
              "name": "locale",
              "type": "string",
              "value": "en"
            },
            {
              "id": "16944d67-32ef-4ffc-93b7-c7e53170b0bb",
              "name": "filename",
              "type": "string",
              "value": "northstar-discovery-proposal.pdf"
            },
            {
              "id": "457322fa-b17d-4df3-9781-7076c14eb788",
              "name": "bodyTextColor",
              "type": "string",
              "value": "#1F2937"
            },
            {
              "id": "6c0728d4-f2a9-4098-9cec-dce3b52ca234",
              "name": "headingTextColor",
              "type": "string",
              "value": "#0F766E"
            },
            {
              "id": "938299d4-9f42-4f41-831c-8bc90fb16547",
              "name": "pageNumbers",
              "type": "boolean",
              "value": true
            }
          ]
        },
        "options": {}
      },
      "id": "a7418149-1b04-4cff-b70e-1f1bd3aee138",
      "name": "Publication input",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [-680, 120]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://markdowntopdfconverter.com/api/v2/documents",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpBearerAuth",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Accept",
              "value": "application/json"
            },
            {
              "name": "Idempotency-Key",
              "value": "={{ $execution.id + '-document' }}"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ { taskId: $json.taskId, title: $json.title, revision: { markdown: $json.markdown, parentRevisionId: null, spec: { locale: $json.locale, options: { bodyTextColor: $json.bodyTextColor, headingTextColor: $json.headingTextColor, pageNumbers: $json.pageNumbers }, templateId: $json.templateId } } } }}",
        "options": {
          "response": {
            "response": {
              "responseFormat": "json"
            }
          },
          "timeout": 30000
        }
      },
      "id": "96fa21f7-7d53-411d-a929-f87a329bfb3a",
      "name": "Create document",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [-440, 120]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ 'https://markdowntopdfconverter.com/api/v2/documents/' + $json.document.id + '/publishes' }}",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpBearerAuth",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Accept",
              "value": "application/json"
            },
            {
              "name": "Idempotency-Key",
              "value": "={{ $execution.id + '-publish' }}"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ { output: { filename: $('Publication input').item.json.filename, format: 'pdf' }, revisionId: $json.revision.id } }}",
        "options": {
          "response": {
            "response": {
              "responseFormat": "json"
            }
          },
          "timeout": 30000
        }
      },
      "id": "2af15d51-ae11-4edb-98f1-e5465c19e368",
      "name": "Publish document",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [-200, 120]
    },
    {
      "parameters": {
        "amount": 3,
        "unit": "seconds"
      },
      "id": "55e4eb6f-0080-4bca-99c3-1722193508c6",
      "name": "Wait before status check",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [40, 120]
    },
    {
      "parameters": {
        "url": "={{ 'https://markdowntopdfconverter.com/api/v2/jobs/' + $('Publish document').item.json.job.id }}",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpBearerAuth",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Accept",
              "value": "application/json"
            }
          ]
        },
        "options": {
          "response": {
            "response": {
              "responseFormat": "json"
            }
          },
          "timeout": 30000
        }
      },
      "id": "710d3c91-eaa6-467f-bdcc-2decb8c9790e",
      "name": "Get publishing job",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [280, 120]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "baf7b42c-3f18-4d13-bb74-2b154bf21b69",
              "leftValue": "={{ $json.job.status }}",
              "rightValue": "succeeded",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "55f2b6ec-9db0-4b3b-8bfd-e0aa304413ce",
      "name": "Job succeeded?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [520, 120]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "7bf409f1-6eca-4f76-8082-5d109df7421a",
              "leftValue": "={{ ['failed', 'cancelled'].includes($json.job.status) }}",
              "rightValue": true,
              "operator": {
                "type": "boolean",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "3b182196-5b39-4dbd-907d-b00040143905",
      "name": "Job failed?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [740, 260]
    },
    {
      "parameters": {
        "errorMessage": "={{ 'Publishing job ' + $json.job.id + ' ended as ' + $json.job.status + ': ' + ($json.job.error?.message || 'No details provided.') }}"
      },
      "id": "813f85fc-f08e-4ae7-b7ec-a4c90c1f80c3",
      "name": "Stop on terminal failure",
      "type": "n8n-nodes-base.stopAndError",
      "typeVersion": 1,
      "position": [980, 220]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ 'https://markdowntopdfconverter.com/api/v2/artifacts/' + $('Get publishing job').item.json.artifact.id + '/links' }}",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpBearerAuth",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Accept",
              "value": "application/json"
            }
          ]
        },
        "options": {
          "response": {
            "response": {
              "responseFormat": "json"
            }
          },
          "timeout": 30000
        }
      },
      "id": "3579b14e-3ef6-40b0-a5a6-8fa6a555ebf9",
      "name": "Create private download link",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [760, 0]
    },
    {
      "parameters": {
        "url": "={{ $json.href }}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Accept",
              "value": "application/pdf"
            }
          ]
        },
        "options": {
          "response": {
            "response": {
              "responseFormat": "file",
              "outputPropertyName": "data"
            }
          },
          "timeout": 30000
        }
      },
      "id": "26c55f21-9c16-4eca-ae60-1f1cbec4aa7a",
      "name": "Download verified PDF",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [1000, 0]
    }
  ],
  "connections": {
    "Run workflow": {
      "main": [[{"node": "Publication input", "type": "main", "index": 0}]]
    },
    "Publication input": {
      "main": [[{"node": "Create document", "type": "main", "index": 0}]]
    },
    "Create document": {
      "main": [[{"node": "Publish document", "type": "main", "index": 0}]]
    },
    "Publish document": {
      "main": [[{"node": "Wait before status check", "type": "main", "index": 0}]]
    },
    "Wait before status check": {
      "main": [[{"node": "Get publishing job", "type": "main", "index": 0}]]
    },
    "Get publishing job": {
      "main": [[{"node": "Job succeeded?", "type": "main", "index": 0}]]
    },
    "Job succeeded?": {
      "main": [
        [{"node": "Create private download link", "type": "main", "index": 0}],
        [{"node": "Job failed?", "type": "main", "index": 0}]
      ]
    },
    "Job failed?": {
      "main": [
        [{"node": "Stop on terminal failure", "type": "main", "index": 0}],
        [{"node": "Wait before status check", "type": "main", "index": 0}]
      ]
    },
    "Create private download link": {
      "main": [[{"node": "Download verified PDF", "type": "main", "index": 0}]]
    }
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1",
    "saveDataErrorExecution": "all",
    "saveDataSuccessExecution": "none",
    "saveManualExecutions": false
  },
  "tags": []
}
