{
  "name": "CAAS - Async Document to Markdown with Polling",
  "nodes": [
    {
      "id": "6a1b2c3d-0001",
      "name": "Schedule Trigger",
      "type": "n8n-nodes-base.ScheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        250,
        300
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "minutes",
              "minutesInterval": 1
            }
          ]
        }
      }
    },
    {
      "parameters": {
        "operation": "fromUrl",
        "url": "={{ $env.PDF_URL || 'https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf' }}",
        "options": {}
      },
      "id": "6a1b2c3d-0002",
      "name": "Download File",
      "type": "n8n-nodes-base.ReadWriteFile",
      "typeVersion": 1,
      "position": [
        450,
        300
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $env.CAAS_URL || 'http://localhost:8000' }}/convert?async=true",
        "sendFiles": true,
        "fileKey": "file",
        "options": {
          "timeout": 30000
        }
      },
      "id": "6a1b2c3d-0003",
      "name": "Submit to CAAS",
      "type": "n8n-nodes-base.HttpRequest",
      "typeVersion": 4.2,
      "position": [
        650,
        300
      ]
    },
    {
      "parameters": {
        "method": "GET",
        "url": "={{ $env.CAAS_URL || 'http://localhost:8000' }}/task/{{ $json.task_id }}",
        "options": {
          "timeout": 30000
        }
      },
      "id": "6a1b2c3d-0004",
      "name": "Poll Task Status",
      "type": "n8n-nodes-base.HttpRequest",
      "typeVersion": 4.2,
      "position": [
        850,
        300
      ]
    },
    {
      "parameters": {
        "content": "={{ $('Submit to CAAS').first().json.task_id }}",
        "assignKey": "task_id"
      },
      "id": "6a1b2c3d-0005",
      "name": "Extract Task ID",
      "type": "n8n-nodes-base.Set",
      "typeVersion": 3.4,
      "position": [
        750,
        300
      ]
    },
    {
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{ $json.status }}",
              "value2": "Completed"
            }
          ]
        }
      },
      "id": "6a1b2c3d-0006",
      "name": "Task Complete?",
      "type": "n8n-nodes-base.If",
      "typeVersion": 2,
      "position": [
        1050,
        300
      ]
    },
    {
      "parameters": {
        "content": "## Async Conversion Workflow\n\nThis workflow demonstrates asynchronous conversion via CAAS:\n\n### Supported Formats:\nPDF, DOCX, ODT, ODP, ODS, HTML, XLSX, PPTX\n\n### Steps:\n1. **Download File**: Downloads a file from a URL\n2. **Submit to CAAS**: POST /convert?async=true \u2192 returns a task_id\n3. **Extract Task ID**: Extracts the task_id from the response\n4. **Poll Task Status**: GET /task/{task_id} to check progress\n5. **Task Complete?**: Condition \u2014 if \"Completed\", retrieves the result\n\n### Required Environment:\n- `CAAS_URL`: CAAS API URL (e.g., http://localhost:8000)\n- `PDF_URL`: URL of the file to convert (optional)",
        "height": 320,
        "width": 420
      },
      "id": "6a1b2c3d-0007",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.StickyNote",
      "typeVersion": 1,
      "position": [
        250,
        80
      ]
    },
    {
      "parameters": {
        "operation": "set",
        "version": 2,
        "fields": {
          "content": {
            "mode": "name",
            "name": "markdown",
            "value": "={{ $json.result.markdown }}"
          },
          "filename": {
            "mode": "name",
            "name": "original_filename",
            "value": "={{ $json.result.filename }}"
          },
          "pages": {
            "mode": "name",
            "name": "page_count",
            "value": "={{ $json.result.pages }}"
          }
        },
        "options": {}
      },
      "id": "6a1b2c3d-0008",
      "name": "Extract Markdown",
      "type": "n8n-nodes-base.Set",
      "typeVersion": 3.4,
      "position": [
        1250,
        300
      ]
    }
  ],
  "connections": {
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Download File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download File": {
      "main": [
        [
          {
            "node": "Submit to CAAS",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Submit to CAAS": {
      "main": [
        [
          {
            "node": "Extract Task ID",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Task ID": {
      "main": [
        [
          {
            "node": "Poll Task Status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Poll Task Status": {
      "main": [
        [
          {
            "node": "Task Complete?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Task Complete?": {
      "main": [
        [
          {
            "node": "Extract Markdown",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "1",
  "id": "caas-workflow-async",
  "tags": []
}