{
  "id": "doqlo-failure-handling",
  "name": "Doqlo Bulk Fill - Failure Handling",
  "nodes": [
    {
      "parameters": {},
      "id": "manual-trigger",
      "name": "Manual Trigger",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        260,
        260
      ]
    },
    {
      "parameters": {
        "mode": "manual",
        "fields": {
          "values": [
            {
              "name": "api_base_url",
              "type": "stringValue",
              "stringValue": "https://api.doqlo.com"
            },
            {
              "name": "bf_export_api_key",
              "type": "stringValue",
              "stringValue": "replace-with-your-bf-export-api-key"
            },
            {
              "name": "source_pdf_url",
              "type": "stringValue",
              "stringValue": "https://example.com/source.pdf"
            },
            {
              "name": "invalid_doqlo_url",
              "type": "stringValue",
              "stringValue": "https://example.com/invalid-template.doqlo"
            },
            {
              "name": "rows_json",
              "type": "stringValue",
              "stringValue": "[{\"column_0\":\"Alice Example\"}]"
            },
            {
              "name": "max_failed_row_percent",
              "type": "stringValue",
              "stringValue": "0"
            }
          ]
        },
        "include": "all",
        "options": {}
      },
      "id": "set-failure-example-inputs",
      "name": "Set Failure Example Inputs",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.2,
      "position": [
        520,
        260
      ]
    },
    {
      "parameters": {
        "method": "GET",
        "url": "={{$node[\"Set Failure Example Inputs\"].json[\"source_pdf_url\"]}}",
        "authentication": "none",
        "options": {
          "response": {
            "responseFormat": "file",
            "outputPropertyName": "pdf"
          }
        }
      },
      "id": "download-source-pdf",
      "name": "Download Source PDF",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        760,
        160
      ]
    },
    {
      "parameters": {
        "method": "GET",
        "url": "={{$node[\"Set Failure Example Inputs\"].json[\"invalid_doqlo_url\"]}}",
        "authentication": "none",
        "options": {
          "response": {
            "responseFormat": "file",
            "outputPropertyName": "doqlo_file"
          }
        }
      },
      "id": "download-invalid-doqlo-package",
      "name": "Download Invalid Doqlo Package",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        760,
        360
      ]
    },
    {
      "parameters": {
        "mode": "combine",
        "combineBy": "combineByPosition",
        "numberInputs": 2,
        "options": {}
      },
      "id": "merge-job-inputs",
      "name": "Merge Job Inputs",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 3.2,
      "position": [
        1000,
        260
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{$node[\"Set Failure Example Inputs\"].json[\"api_base_url\"] + \"/v1/bulkfill/export-jobs\"}}",
        "authentication": "none",
        "sendHeaders": true,
        "specifyHeaders": "keypair",
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "={{\"Bearer \" + $node[\"Set Failure Example Inputs\"].json[\"bf_export_api_key\"]}}"
            },
            {
              "name": "Idempotency-Key",
              "value": "={{\"doqlo-failure-\" + $now.toMillis()}}"
            }
          ]
        },
        "sendBody": true,
        "contentType": "multipart-form-data",
        "bodyParameters": {
          "parameters": [
            {
              "parameterType": "formBinaryData",
              "name": "pdf",
              "inputDataFieldName": "pdf"
            },
            {
              "parameterType": "formBinaryData",
              "name": "doqlo_file",
              "inputDataFieldName": "doqlo_file"
            },
            {
              "parameterType": "formData",
              "name": "rows_json",
              "value": "={{$node[\"Set Failure Example Inputs\"].json[\"rows_json\"]}}"
            },
            {
              "parameterType": "formData",
              "name": "max_failed_row_percent",
              "value": "={{$node[\"Set Failure Example Inputs\"].json[\"max_failed_row_percent\"]}}"
            }
          ]
        },
        "options": {
          "response": {
            "fullResponse": true,
            "neverError": true,
            "responseFormat": "json"
          }
        }
      },
      "id": "create-export-job",
      "name": "Create Export Job",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        1240,
        260
      ]
    },
    {
      "parameters": {
        "conditions": {
          "number": [
            {
              "value1": "={{$json[\"statusCode\"] || 0}}",
              "operation": "largerEqual",
              "value2": 400
            }
          ]
        }
      },
      "id": "did-request-fail",
      "name": "Did Request Fail?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        1480,
        160
      ]
    },
    {
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{($json[\"body\"] && $json[\"body\"][\"status\"]) || \"\"}}",
              "operation": "equal",
              "value2": "failed"
            }
          ]
        }
      },
      "id": "did-job-fail",
      "name": "Did Job Fail?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        1480,
        360
      ]
    },
    {
      "parameters": {
        "mode": "manual",
        "fields": {
          "values": [
            {
              "name": "http_status",
              "type": "stringValue",
              "stringValue": "={{String($json[\"statusCode\"] || 0)}}"
            },
            {
              "name": "job_id",
              "type": "stringValue",
              "stringValue": "={{($json[\"body\"] && $json[\"body\"][\"job_id\"]) || \"\"}}"
            },
            {
              "name": "error_code",
              "type": "stringValue",
              "stringValue": "={{($json[\"body\"] && $json[\"body\"][\"error\"] && $json[\"body\"][\"error\"][\"code\"]) || \"\"}}"
            },
            {
              "name": "error_message",
              "type": "stringValue",
              "stringValue": "={{($json[\"body\"] && $json[\"body\"][\"error\"] && $json[\"body\"][\"error\"][\"message\"]) || \"\"}}"
            },
            {
              "name": "error_details",
              "type": "stringValue",
              "stringValue": "={{JSON.stringify((($json[\"body\"] && $json[\"body\"][\"error\"] && $json[\"body\"][\"error\"][\"details\"]) || {}))}}"
            },
            {
              "name": "request_id",
              "type": "stringValue",
              "stringValue": "={{($json[\"headers\"] && ($json[\"headers\"][\"x-request-id\"] || $json[\"headers\"][\"X-Request-Id\"])) || \"\"}}"
            }
          ]
        },
        "include": "all",
        "options": {}
      },
      "id": "preserve-error-details",
      "name": "Preserve Error Details",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.2,
      "position": [
        1720,
        260
      ]
    },
    {
      "parameters": {
        "mode": "manual",
        "fields": {
          "values": [
            {
              "name": "status",
              "type": "stringValue",
              "stringValue": "unexpected-success"
            },
            {
              "name": "message",
              "type": "stringValue",
              "stringValue": "This failure example did not fail. Replace invalid_doqlo_url with an intentionally bad file URL or another known failure case."
            }
          ]
        },
        "include": "all",
        "options": {}
      },
      "id": "unexpected-success",
      "name": "Unexpected Success",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.2,
      "position": [
        1720,
        460
      ]
    }
  ],
  "connections": {
    "Manual Trigger": {
      "main": [
        [
          {
            "node": "Set Failure Example Inputs",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Failure Example Inputs": {
      "main": [
        [
          {
            "node": "Download Source PDF",
            "type": "main",
            "index": 0
          },
          {
            "node": "Download Invalid Doqlo Package",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download Source PDF": {
      "main": [
        [
          {
            "node": "Merge Job Inputs",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download Invalid Doqlo Package": {
      "main": [
        [
          {
            "node": "Merge Job Inputs",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Merge Job Inputs": {
      "main": [
        [
          {
            "node": "Create Export Job",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Export Job": {
      "main": [
        [
          {
            "node": "Did Request Fail?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Did Request Fail?": {
      "main": [
        [
          {
            "node": "Preserve Error Details",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Did Job Fail?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Did Job Fail?": {
      "main": [
        [
          {
            "node": "Preserve Error Details",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Unexpected Success",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "4e36242d-c712-4e86-9a39-995175be8bf9",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "tags": []
}
