{
 "name": "MajorDTF DTF Prep API \u2014 starter (webhook in, print file out)",
 "nodes": [
  {
   "parameters": {
    "content": "## MajorDTF DTF-prep starter\n\nPOST any artwork URL to the webhook and get back a print-ready 300 DPI transparent PNG (background removed, sized to print width, hard alpha edges).\n\n**Setup (2 minutes):**\n1. Mint an API key at https://www.majordtf.com/account \u2192 API keys (`mdtf_live_...`).\n2. Create an n8n **Bearer Auth** credential with that key and assign it to the `MajorDTF - Prep Artwork` node.\n3. Activate, then call the production webhook:\n\n```\ncurl -X POST <your-webhook-url> \\\n  -H 'Content-Type: application/json' \\\n  -d '{\"image_url\":\"https://example.com/logo.png\",\"width_in\":11,\"garment_color\":\"#1a1a1a\"}'\n```\n\n`garment_color` is optional \u2014 pass the shirt hex to knock that colour out and blend halftones against it. 1 credit per successful prep. The returned `file_url` is signed for 24 h; this workflow downloads it and returns the PNG bytes directly so you don't have to.\n\nSwap the last node for a Google Drive / Dropbox / S3 upload if you'd rather store the file than return it.",
    "height": 460,
    "width": 420
   },
   "id": "note1",
   "name": "How this works",
   "type": "n8n-nodes-base.stickyNote",
   "typeVersion": 1,
   "position": [
    -780,
    -160
   ]
  },
  {
   "parameters": {
    "httpMethod": "POST",
    "path": "dtf-prep",
    "responseMode": "responseNode",
    "options": {}
   },
   "id": "n1",
   "name": "Webhook - Artwork In",
   "type": "n8n-nodes-base.webhook",
   "typeVersion": 2,
   "position": [
    -320,
    80
   ]
  },
  {
   "parameters": {
    "jsCode": "const b = $json.body || {};\nif (!b.image_url) {\n  return [{ json: { error: 'image_url is required', ok: false } }];\n}\nreturn [{ json: {\n  ok: true,\n  image_url: String(b.image_url),\n  print_width_in: Number(b.width_in || b.print_width_in || 11),\n  garment_colors: b.garment_color ? [String(b.garment_color)] : undefined,\n  thickness_protection: Boolean(b.thickness_protection || false)\n}}];"
   },
   "id": "n2",
   "name": "Validate Input",
   "type": "n8n-nodes-base.code",
   "typeVersion": 2,
   "position": [
    -100,
    80
   ]
  },
  {
   "parameters": {
    "conditions": {
     "options": {
      "caseSensitive": true,
      "leftValue": "",
      "typeValidation": "strict",
      "version": 2
     },
     "conditions": [
      {
       "leftValue": "={{ $json.ok }}",
       "rightValue": true,
       "operator": {
        "type": "boolean",
        "operation": "true",
        "singleValue": true
       }
      }
     ],
     "combinator": "and"
    }
   },
   "id": "n3",
   "name": "IF Valid",
   "type": "n8n-nodes-base.if",
   "typeVersion": 2.2,
   "position": [
    120,
    80
   ]
  },
  {
   "parameters": {
    "method": "POST",
    "url": "https://worker.majordtf.com/v1/prep",
    "authentication": "genericCredentialType",
    "genericAuthType": "httpBearerAuth",
    "sendBody": true,
    "specifyBody": "json",
    "jsonBody": "={{ JSON.stringify({ image_url: $json.image_url, print_width_in: $json.print_width_in, garment_colors: $json.garment_colors, thickness_protection: $json.thickness_protection }) }}",
    "options": {
     "timeout": 120000
    }
   },
   "id": "n4",
   "name": "MajorDTF - Prep Artwork",
   "type": "n8n-nodes-base.httpRequest",
   "typeVersion": 4.2,
   "position": [
    340,
    0
   ]
  },
  {
   "parameters": {
    "conditions": {
     "options": {
      "caseSensitive": true,
      "leftValue": "",
      "typeValidation": "loose",
      "version": 2
     },
     "conditions": [
      {
       "leftValue": "={{ $json.file_url }}",
       "rightValue": "",
       "operator": {
        "type": "string",
        "operation": "notEmpty",
        "singleValue": true
       }
      }
     ],
     "combinator": "and"
    }
   },
   "id": "n5",
   "name": "IF Prep OK",
   "type": "n8n-nodes-base.if",
   "typeVersion": 2.2,
   "position": [
    560,
    0
   ]
  },
  {
   "parameters": {
    "url": "={{ $json.file_url }}",
    "options": {
     "response": {
      "response": {
       "responseFormat": "file"
      }
     },
     "timeout": 120000
    }
   },
   "id": "n6",
   "name": "Download Print File",
   "type": "n8n-nodes-base.httpRequest",
   "typeVersion": 4.2,
   "position": [
    780,
    -80
   ]
  },
  {
   "parameters": {
    "respondWith": "binary",
    "options": {
     "responseHeaders": {
      "entries": [
       {
        "name": "Content-Type",
        "value": "image/png"
       },
       {
        "name": "Content-Disposition",
        "value": "attachment; filename=\"print-ready.png\""
       }
      ]
     }
    }
   },
   "id": "n7",
   "name": "Respond With PNG",
   "type": "n8n-nodes-base.respondToWebhook",
   "typeVersion": 1.1,
   "position": [
    1000,
    -80
   ]
  },
  {
   "parameters": {
    "respondWith": "json",
    "responseBody": "={{ JSON.stringify({ error: $json.error || 'prep failed', detail: $json }) }}",
    "options": {
     "responseCode": 422
    }
   },
   "id": "n8",
   "name": "Respond With Error",
   "type": "n8n-nodes-base.respondToWebhook",
   "typeVersion": 1.1,
   "position": [
    560,
    240
   ]
  }
 ],
 "connections": {
  "Webhook - Artwork In": {
   "main": [
    [
     {
      "node": "Validate Input",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "Validate Input": {
   "main": [
    [
     {
      "node": "IF Valid",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "IF Valid": {
   "main": [
    [
     {
      "node": "MajorDTF - Prep Artwork",
      "type": "main",
      "index": 0
     }
    ],
    [
     {
      "node": "Respond With Error",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "MajorDTF - Prep Artwork": {
   "main": [
    [
     {
      "node": "IF Prep OK",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "IF Prep OK": {
   "main": [
    [
     {
      "node": "Download Print File",
      "type": "main",
      "index": 0
     }
    ],
    [
     {
      "node": "Respond With Error",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "Download Print File": {
   "main": [
    [
     {
      "node": "Respond With PNG",
      "type": "main",
      "index": 0
     }
    ]
   ]
  }
 },
 "settings": {
  "executionOrder": "v1"
 },
 "pinData": {}
}