{
  "name": "Scraper · quote, scrape, complete result",
  "active": false,
  "settings": { "executionOrder": "v1" },
  "nodes": [
    { "id": "notes", "name": "Setup", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, "position": [-440,-260], "parameters": { "width": 700, "height": 230, "content": "## Setup\n1. Edit the API base URL and target URL in Configure.\n2. Create an HTTP Header Auth credential: name Authorization, value Bearer sg_YOUR_KEY. Select it in Quote, Create job, Job status and Result.\n3. Execute manually. The quote is approved for this execution; Auto charges successful jobs only. All result formats are returned.\nPolling stops on failure or after five minutes. Resume an existing job through the SDK or API instead of starting a new workflow if the reply was lost. Never paste your key into workflow JSON." } },
    { "id": "trigger", "name": "Start", "type": "n8n-nodes-base.manualTrigger", "typeVersion": 1, "position": [-440,40], "parameters": {} },
    { "id": "configure", "name": "Configure", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [-220,40], "parameters": { "jsCode": "return [{json:{base:'https://YOUR_SCRAPER_HOST/api/v1', request:{target_url:'https://example.com/',idempotency_key:'n8n-'+$execution.id,request_payload:{content:{main:true}}},deadline:Date.now()+300000}}];" } },
    { "id": "quote", "name": "Quote", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [0,40], "parameters": { "method": "POST", "url": "={{ $('Configure').first().json.base + '/pricing/quote' }}", "authentication": "genericCredentialType", "genericAuthType": "httpHeaderAuth", "sendBody": true, "specifyBody": "json", "jsonBody": "={{ $('Configure').first().json.request }}", "options": { "timeout": 30000, "redirect": { "redirect": { "followRedirects": false } } } } },
    { "id": "create", "name": "Create job", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [220,40], "parameters": { "method": "POST", "url": "={{ $('Configure').first().json.base + '/jobs' }}", "authentication": "genericCredentialType", "genericAuthType": "httpHeaderAuth", "sendBody": true, "specifyBody": "json", "jsonBody": "={{ { ...$('Configure').first().json.request, max_cost: $json.cost } }}", "options": { "timeout": 30000, "redirect": { "redirect": { "followRedirects": false } } } } },
    { "id": "wait", "name": "Wait", "type": "n8n-nodes-base.wait", "typeVersion": 1.1, "position": [440,40], "parameters": { "amount": 2, "unit": "seconds" }, "webhookId": "3c182f33-825b-471b-a34d-876f85c70b01" },
    { "id": "status", "name": "Job status", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [660,40], "parameters": { "url": "={{ $('Configure').first().json.base + '/jobs/' + $('Create job').first().json.job_id }}", "authentication": "genericCredentialType", "genericAuthType": "httpHeaderAuth", "options": { "timeout": 30000, "redirect": { "redirect": { "followRedirects": false } } } } },
    { "id": "check", "name": "Check terminal state", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [880,40], "parameters": { "jsCode": "if (['dead','canceled'].includes($json.status)) throw new Error('Scrape '+$json.status+': '+($json.error_message || '')); if (Date.now()>$('Configure').first().json.deadline) throw new Error('Polling deadline: resume job '+$('Create job').first().json.job_id+' through the API'); return $input.all();" } },
    { "id": "ready", "name": "Succeeded", "type": "n8n-nodes-base.if", "typeVersion": 2.2, "position": [1100,40], "parameters": { "conditions": { "options": { "caseSensitive": true, "typeValidation": "strict", "version": 2 }, "conditions": [{ "id": "status-condition", "leftValue": "={{ $json.status }}", "rightValue": "succeeded", "operator": { "type": "string", "operation": "equals" } }], "combinator": "and" }, "options": {} } },
    { "id": "result", "name": "Result", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [1320,-40], "parameters": { "url": "={{ $('Configure').first().json.base + '/jobs/' + $('Create job').first().json.job_id + '/result' }}", "authentication": "genericCredentialType", "genericAuthType": "httpHeaderAuth", "options": { "timeout": 30000, "redirect": { "redirect": { "followRedirects": false } } } } }
  ],
  "connections": {
    "Start": { "main": [[{ "node": "Configure", "type": "main", "index": 0 }]] },
    "Configure": { "main": [[{ "node": "Quote", "type": "main", "index": 0 }]] },
    "Quote": { "main": [[{ "node": "Create job", "type": "main", "index": 0 }]] },
    "Create job": { "main": [[{ "node": "Wait", "type": "main", "index": 0 }]] },
    "Wait": { "main": [[{ "node": "Job status", "type": "main", "index": 0 }]] },
    "Job status": { "main": [[{ "node": "Check terminal state", "type": "main", "index": 0 }]] },
    "Check terminal state": { "main": [[{ "node": "Succeeded", "type": "main", "index": 0 }]] },
    "Succeeded": { "main": [[{ "node": "Result", "type": "main", "index": 0 }], [{ "node": "Wait", "type": "main", "index": 0 }]] }
  }
}
