{
  "name": "North America Driver License Front + Back PDF417 Verification (StructOCR)",
  "nodes": [
    {
      "parameters": {
        "content": "## Driver License Front + Back Verification (Zero Data Retention)\nUpload the front and back of a US or Canadian driver license or State ID (JPG, PNG, WebP, or native iPhone HEIC up to 4.5 MB each).\n\nStructOCR decodes the back AAMVA PDF417 barcode first, OCRs the printed front, and runs deterministic cross-checks (ID number, name, DOB, expiry, state/province, DD vs DCF, and age threshold).\n\n- **Zero Data Retention**: Images and identity payloads are never stored.\n- **Auto-Refund on 422**: Blurry or cropped back barcodes short-circuit with HTTP 422 and automatically refund all 4 credits.\n- **Scope**: Card-level front/back consistency check only; does not query DMV registries.\n\n**Setup**\n1. Get a free API key (200 permanent credits = 50 full checks) at https://structocr.com/register?utm_source=n8n_template&utm_medium=workflow&utm_campaign=dl_verify\n2. In the StructOCR HTTP Request node, create a Header Auth credential: Name `x-api-key`, Value = your key.\n3. Open the Form Trigger URL and upload front + back photos (optional custom `min_age`, default 21).\n\nFull Guide: https://structocr.com/blog/platforms/n8n-driver-license-verification",
        "height": 480,
        "width": 500
      },
      "id": "note-1",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -560,
        -180
      ]
    },
    {
      "parameters": {
        "formTitle": "Driver License Front & Back Verification",
        "formDescription": "Upload both sides of a US or Canadian driver license or State ID (JPG, PNG, WebP, or iPhone HEIC, up to 4.5 MB each). Images are processed in memory with zero data retention.",
        "formFields": {
          "values": [
            {
              "fieldLabel": "front",
              "fieldType": "file",
              "multipleFiles": false,
              "acceptFileTypes": ".jpg,.jpeg,.png,.webp,.heic,.heif",
              "requiredField": true
            },
            {
              "fieldLabel": "back",
              "fieldType": "file",
              "multipleFiles": false,
              "acceptFileTypes": ".jpg,.jpeg,.png,.webp,.heic,.heif",
              "requiredField": true
            },
            {
              "fieldLabel": "min_age",
              "fieldType": "number",
              "placeholder": "21",
              "requiredField": false
            }
          ]
        },
        "options": {}
      },
      "id": "trigger-1",
      "name": "Upload License Front & Back",
      "type": "n8n-nodes-base.formTrigger",
      "typeVersion": 2.2,
      "position": [
        0,
        0
      ],
      "webhookId": "9a7d4e21-8c3f-4b5a-a2d1-6f0e3b9c4182"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.structocr.com/v1/driver-license-verify",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendBody": true,
        "contentType": "multipart-form-data",
        "bodyParameters": {
          "parameters": [
            {
              "parameterType": "formBinaryData",
              "name": "front",
              "inputDataFieldName": "front"
            },
            {
              "parameterType": "formBinaryData",
              "name": "back",
              "inputDataFieldName": "back"
            },
            {
              "parameterType": "formData",
              "name": "min_age",
              "value": "={{ $json.min_age || '21' }}"
            }
          ]
        },
        "options": {
          "response": {
            "response": {
              "neverError": true
            }
          }
        }
      },
      "id": "http-1",
      "name": "StructOCR Verify Driver License",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        260,
        0
      ],
      "credentials": {
        "httpHeaderAuth": {
          "id": "",
          "name": "StructOCR API key"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "// n8n Code node — Run Once for All Items (JavaScript)\n// Normalizes POST /v1/driver-license-verify into 3 deterministic routes:\n//   - 'approved'        : verified_match, not expired, meets min_age\n//   - 'retake_required' : HTTP 422 / capture error (0 credits charged; auto-refunded)\n//   - 'manual_review'   : mismatch, expired, underage, inconclusive, or other API error\nconst output = [];\n\nfor (const item of $input.all()) {\n  const res = item.json || {};\n\n  if (!res.success) {\n    const isCaptureIssue = Boolean(res.failed_side || res.capture_issue);\n    output.push({\n      json: {\n        route: isCaptureIssue ? 'retake_required' : 'manual_review',\n        ok: false,\n        error: res.error ?? 'VERIFY_FAILED',\n        message: res.message ?? 'Verification failed.',\n        failed_side: res.failed_side ?? null,\n        capture_issue: res.capture_issue ?? null,\n        credits_charged: 0,\n      },\n    });\n    continue;\n  }\n\n  const v = res.data?.verification ?? {};\n  const front = res.data?.front ?? {};\n  const back = res.data?.back ?? {};\n  const agePassed = v.meets_min_age !== false;\n  const isApproved = v.overall_status === 'verified_match' && v.is_expired === false && agePassed;\n\n  output.push({\n    json: {\n      route: isApproved ? 'approved' : 'manual_review',\n      ok: true,\n      overall_status: v.overall_status ?? 'inconclusive',\n      front_back_match: Boolean(v.front_back_match),\n      dd_dcf_match: v.dd_dcf_match ?? 'unavailable',\n      is_expired: v.is_expired ?? null,\n      age_years: v.age_years ?? null,\n      is_over_18: v.is_over_18 ?? null,\n      is_over_21: v.is_over_21 ?? null,\n      meets_min_age: v.meets_min_age ?? null,\n      mismatches: v.mismatches ?? [],\n      document_number: back.document_number ?? front.document_number ?? null,\n      surname: back.surname ?? front.surname ?? null,\n      given_names: back.given_names ?? front.given_names ?? null,\n      date_of_birth: back.date_of_birth ?? front.date_of_birth ?? null,\n      date_of_expiry: back.date_of_expiry ?? front.date_of_expiry ?? null,\n      region: back.region ?? front.region ?? null,\n      country_code: back.country_code ?? front.country_code ?? null,\n      aamva_version: back.aamva_version ?? null,\n      scope_notice: v.scope_notice ?? 'Card-level front/back consistency check only; does not query DMV or government registries.',\n      credits_charged: 4,\n    },\n  });\n}\n\nreturn output;"
      },
      "id": "code-1",
      "name": "Evaluate Verification Outcome",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        520,
        0
      ]
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "cond-approved",
                    "leftValue": "={{ $json.route }}",
                    "rightValue": "approved",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Approved"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "cond-retake",
                    "leftValue": "={{ $json.route }}",
                    "rightValue": "retake_required",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Retake Required (422)"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "cond-review",
                    "leftValue": "={{ $json.route }}",
                    "rightValue": "manual_review",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Manual Review"
            }
          ]
        },
        "options": {}
      },
      "id": "switch-1",
      "name": "Route by Decision",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.2,
      "position": [
        780,
        0
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "assign-approved-status",
              "name": "decision",
              "value": "approved",
              "type": "string"
            },
            {
              "id": "assign-approved-next",
              "name": "next_action",
              "value": "Connect your CRM, Postgres, Airtable, or onboarding webhook here.",
              "type": "string"
            }
          ]
        },
        "includeOtherFields": true,
        "options": {}
      },
      "id": "set-approved",
      "name": "Approved Record",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        1060,
        -180
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "assign-retake-status",
              "name": "decision",
              "value": "retake_required",
              "type": "string"
            },
            {
              "id": "assign-retake-prompt",
              "name": "user_prompt",
              "value": "={{ 'Please retake the ' + ($json.failed_side || 'back') + ' photo: ' + ($json.message || 'Make sure the PDF417 barcode is sharp and glare-free.') }}",
              "type": "string"
            }
          ]
        },
        "includeOtherFields": true,
        "options": {}
      },
      "id": "set-retake",
      "name": "Retake Prompt (Auto-Refunded)",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        1060,
        0
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "assign-review-status",
              "name": "decision",
              "value": "manual_review",
              "type": "string"
            },
            {
              "id": "assign-review-reason",
              "name": "review_reason",
              "value": "={{ $json.overall_status === 'mismatch' ? ('Front/back mismatch on: ' + ($json.mismatches || []).join(', ')) : ($json.overall_status === 'expired' ? 'License expired' : ($json.meets_min_age === false ? 'Cardholder does not meet min_age' : ($json.message || $json.overall_status || 'Manual review required'))) }}",
              "type": "string"
            }
          ]
        },
        "includeOtherFields": true,
        "options": {}
      },
      "id": "set-review",
      "name": "Flag for Manual Review",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        1060,
        180
      ]
    }
  ],
  "connections": {
    "Upload License Front & Back": {
      "main": [
        [
          {
            "node": "StructOCR Verify Driver License",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "StructOCR Verify Driver License": {
      "main": [
        [
          {
            "node": "Evaluate Verification Outcome",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Evaluate Verification Outcome": {
      "main": [
        [
          {
            "node": "Route by Decision",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Route by Decision": {
      "main": [
        [
          {
            "node": "Approved Record",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Retake Prompt (Auto-Refunded)",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Flag for Manual Review",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "meta": {
    "templateCredsSetupCompleted": false
  }
}
