{
  "name": "Publish a polished Markdown PDF",
  "flow": [
    {
      "id": 1,
      "module": "http:ActionSendDataAPIKeyAuth",
      "version": 3,
      "parameters": {
        "auth": 0,
        "handleErrors": true
      },
      "mapper": {
        "url": "https://markdowntopdfconverter.com/api/v2/documents",
        "serializeUrl": false,
        "method": "post",
        "headers": [
          {"name": "Accept", "value": "application/json"},
          {"name": "Idempotency-Key", "value": "make-{{formatDate(now; \"x\")}}-document"}
        ],
        "qs": [],
        "bodyType": "raw",
        "contentType": "application/json",
        "data": "{\"revision\":{\"markdown\":\"# 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.\",\"parentRevisionId\":null,\"spec\":{\"locale\":\"en\",\"options\":{\"bodyTextColor\":\"#1F2937\",\"headingTextColor\":\"#0F766E\",\"pageNumbers\":true},\"templateId\":\"proposal-consulting\"}},\"taskId\":\"consulting-proposal\",\"title\":\"Northstar discovery proposal\"}",
        "parseResponse": true,
        "timeout": "30",
        "shareCookies": false,
        "ca": "",
        "rejectUnauthorized": true,
        "followRedirect": true,
        "useQuerystring": false,
        "gzip": true,
        "useMtls": false,
        "followAllRedirects": false
      },
      "metadata": {
        "designer": {"x": 0, "y": 0, "name": "Create document"},
        "parameters": [
          {"name": "auth", "type": "keychain:apikeyauth", "label": "Credentials", "required": true},
          {"name": "handleErrors", "type": "boolean", "label": "Evaluate non-success responses as errors", "required": true}
        ]
      }
    },
    {
      "id": 2,
      "module": "http:ActionSendDataAPIKeyAuth",
      "version": 3,
      "parameters": {
        "auth": 0,
        "handleErrors": true
      },
      "mapper": {
        "url": "https://markdowntopdfconverter.com/api/v2/documents/{{1.data.document.id}}/publishes",
        "serializeUrl": false,
        "method": "post",
        "headers": [
          {"name": "Accept", "value": "application/json"},
          {"name": "Idempotency-Key", "value": "{{1.data.document.id}}-publish"}
        ],
        "qs": [],
        "bodyType": "raw",
        "contentType": "application/json",
        "data": "{\"output\":{\"filename\":\"northstar-discovery-proposal.pdf\",\"format\":\"pdf\"},\"revisionId\":\"{{1.data.revision.id}}\"}",
        "parseResponse": true,
        "timeout": "30",
        "shareCookies": false,
        "ca": "",
        "rejectUnauthorized": true,
        "followRedirect": true,
        "useQuerystring": false,
        "gzip": true,
        "useMtls": false,
        "followAllRedirects": false
      },
      "metadata": {"designer": {"x": 300, "y": 0, "name": "Publish document"}}
    },
    {
      "id": 3,
      "module": "util:SetVariable2",
      "version": 1,
      "parameters": {},
      "mapper": {"name": "pdfDownloaded", "scope": "roundtrip", "value": "false"},
      "metadata": {"designer": {"x": 600, "y": 0, "name": "Initialize download guard"}}
    },
    {
      "id": 4,
      "module": "builtin:BasicRepeater",
      "version": 1,
      "parameters": {},
      "mapper": {"start": "1", "repeats": "20", "step": "1"},
      "metadata": {"designer": {"x": 900, "y": 0, "name": "Poll up to 60 seconds"}}
    },
    {
      "id": 5,
      "module": "util:GetVariable2",
      "version": 1,
      "parameters": {},
      "mapper": {"name": "pdfDownloaded"},
      "metadata": {"designer": {"x": 1200, "y": 0, "name": "Check download guard"}}
    },
    {
      "id": 6,
      "module": "util:FunctionSleep",
      "version": 1,
      "parameters": {},
      "filter": {
        "name": "Continue while no PDF has downloaded",
        "conditions": [[{"a": "{{5.pdfDownloaded}}", "o": "text:notequal", "b": "true"}]]
      },
      "mapper": {"duration": "3"},
      "metadata": {"designer": {"x": 1500, "y": 0, "name": "Wait 3 seconds"}}
    },
    {
      "id": 7,
      "module": "http:ActionSendDataAPIKeyAuth",
      "version": 3,
      "parameters": {"auth": 0, "handleErrors": true},
      "mapper": {
        "url": "https://markdowntopdfconverter.com/api/v2/jobs/{{2.data.job.id}}",
        "serializeUrl": false,
        "method": "get",
        "headers": [{"name": "Accept", "value": "application/json"}],
        "qs": [],
        "bodyType": "",
        "parseResponse": true,
        "timeout": "30",
        "shareCookies": false,
        "ca": "",
        "rejectUnauthorized": true,
        "followRedirect": true,
        "useQuerystring": false,
        "gzip": true,
        "useMtls": false,
        "followAllRedirects": false
      },
      "metadata": {"designer": {"x": 1800, "y": 0, "name": "Get publishing job"}}
    },
    {
      "id": 8,
      "module": "http:ActionSendDataAPIKeyAuth",
      "version": 3,
      "parameters": {"auth": 0, "handleErrors": true},
      "filter": {
        "name": "Job succeeded",
        "conditions": [[{"a": "{{7.data.job.status}}", "o": "text:equal", "b": "succeeded"}]]
      },
      "mapper": {
        "url": "https://markdowntopdfconverter.com/api/v2/artifacts/{{7.data.artifact.id}}/links",
        "serializeUrl": false,
        "method": "post",
        "headers": [{"name": "Accept", "value": "application/json"}],
        "qs": [],
        "bodyType": "",
        "parseResponse": true,
        "timeout": "30",
        "shareCookies": false,
        "ca": "",
        "rejectUnauthorized": true,
        "followRedirect": true,
        "useQuerystring": false,
        "gzip": true,
        "useMtls": false,
        "followAllRedirects": false
      },
      "metadata": {"designer": {"x": 2100, "y": 0, "name": "Create private download link"}}
    },
    {
      "id": 9,
      "module": "http:ActionGetFile",
      "version": 3,
      "parameters": {},
      "mapper": {
        "url": "{{8.data.href}}",
        "method": "get",
        "shareCookies": false
      },
      "metadata": {"designer": {"x": 2400, "y": 0, "name": "Download PDF"}}
    },
    {
      "id": 10,
      "module": "util:SetVariable2",
      "version": 1,
      "parameters": {},
      "mapper": {"name": "pdfDownloaded", "scope": "roundtrip", "value": "true"},
      "metadata": {"designer": {"x": 2700, "y": 0, "name": "Stop further downloads"}}
    }
  ],
  "metadata": {
    "instant": false,
    "version": 1,
    "designer": {"orphans": []},
    "scenario": {
      "roundtrips": 1,
      "maxErrors": 3,
      "autoCommit": true,
      "autoCommitTriggerLast": true,
      "sequential": true,
      "confidential": true,
      "dataloss": false,
      "dlq": false
    }
  }
}
