{
  "name": "Contractor License Check (Apify pelicanlabs/contractor-license-check) -> Google Sheets",
  "nodes": [
    {
      "parameters": {
        "content": "## Contractor License Check on Apify (pelicanlabs/contractor-license-check)\n\nReads rows from a Google Sheet, sends up to 500 unchecked rows to the actor in ONE run, and writes the result columns back to the same rows.\n\n### Setup\n1. **Apify token:** open *Run actor (run-sync)* > Credential > Create new > **Header Auth**. Name: `Authorization`. Value: `Bearer ` followed by your token from Apify Console > Settings > API & Integrations.\n2. **Sheet:** in *Read rows* and *Write results* pick your Google Sheets credential, the spreadsheet and the tab. Row 1 must have the input column(s) `License or Name`, `State` and these result columns: `verdict`, `license_number`, `business_name`, `dba`, `status`, `classifications`, `expiration_date`, `bonded`, `workers_comp`, `liability_insured`, `match_confidence`, `source_url`, `source_as_of`.\n3. Column names are set at the top of *Build batch* if yours differ.\n\n**Price:** $0.02 per matched licence (not-found rows are free), charged by Apify to the token's account, plus Apify's small per-run start fee.\nRows that already have a result are skipped, so running again continues where the last run stopped.",
        "height": 520,
        "width": 520
      },
      "id": "b6783daa-ada3-4351-86ce-4bd0ef5d3d87",
      "name": "How to set up",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -620,
        -260
      ],
      "typeVersion": 1
    },
    {
      "parameters": {},
      "id": "437d4b55-b318-4b70-8a64-b64781987f0d",
      "name": "Run checks",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        0,
        0
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "YOUR_GOOGLE_SHEET_ID"
        }
      },
      "id": "ac0411eb-a5a1-4637-8323-fa775ca6d6a4",
      "name": "Read rows",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        220,
        0
      ],
      "typeVersion": 4.5,
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "REPLACE_WITH_YOUR_CREDENTIAL",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "// ---- Settings you can edit ----------------------------------------------------------\nconst VALUE_COLUMN = 'License or Name'; // licence number, or business name\nconst STATE_COLUMN = 'State';           // CA, WA or TX\nconst RESULT_COLUMN = 'verdict';      // rows where this column already has a value are skipped (re-run to continue)\nconst MAX_ROWS = 500;               // rows per execution = one actor run\n// --------------------------------------------------------------------------------------\nconst rows = $input.all().map((i) => i.json)\n  .filter((r) => String(r[VALUE_COLUMN] ?? '').trim() !== '' && String(r[RESULT_COLUMN] ?? '').trim() === '')\n  .slice(0, MAX_ROWS);\nif (!rows.length) return [];\nconst queries = rows.map((r) => (() => { const v = String(r[VALUE_COLUMN]).trim(); const state = String(r[STATE_COLUMN] ?? '').trim(); return /\\d/.test(v) && !/\\s/.test(v) ? { state, license_number: v } : { state, business_name: v }; })());\nreturn [{ json: { row_numbers: rows.map((r) => r.row_number), body: { queries, maxItems: queries.length } } }];"
      },
      "id": "e4b3761f-0c9a-4489-8533-24d3d7638cb6",
      "name": "Build batch",
      "type": "n8n-nodes-base.code",
      "position": [
        440,
        0
      ],
      "typeVersion": 2
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.apify.com/v2/acts/pelicanlabs~contractor-license-check/run-sync-get-dataset-items",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "memory",
              "value": "512"
            },
            {
              "name": "timeout",
              "value": "280"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify($json.body) }}",
        "options": {
          "timeout": 300000,
          "response": {
            "response": {
              "fullResponse": true
            }
          }
        }
      },
      "id": "a84a6803-2a66-4949-8035-7375c9617e9c",
      "name": "Run actor (run-sync)",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        660,
        0
      ],
      "typeVersion": 4.2,
      "credentials": {
        "httpHeaderAuth": {
          "id": "REPLACE_WITH_YOUR_CREDENTIAL",
          "name": "Apify API token (Header Auth)"
        }
      }
    },
    {
      "parameters": {
        "options": {},
        "fieldToSplitOut": "body"
      },
      "id": "98771ff7-de71-4b1d-8586-bec54a6317b4",
      "name": "One item per result",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        880,
        0
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "9e66c303-851b-4f32-8d62-8a09d1bd956d",
              "name": "row_number",
              "type": "number",
              "value": "={{ $('Build batch').first().json.row_numbers[$itemIndex] }}"
            },
            {
              "id": "6061543d-71f5-4e40-8d2d-b96e4b399e68",
              "name": "verdict",
              "type": "string",
              "value": "={{ $json.verdict ?? ('invalid: ' + ($json.error ?? 'no result')) }}"
            },
            {
              "id": "ebd4a10f-4fa1-4598-8409-2eec63bdd007",
              "name": "license_number",
              "type": "string",
              "value": "={{ String($json.license_number ?? '') }}"
            },
            {
              "id": "9e4ddd7a-7cc1-4758-8e08-7ee4f54b6d52",
              "name": "business_name",
              "type": "string",
              "value": "={{ String($json.business_name ?? '') }}"
            },
            {
              "id": "6284b9b8-3851-4eb5-8928-774f85fa3393",
              "name": "dba",
              "type": "string",
              "value": "={{ String($json.dba ?? '') }}"
            },
            {
              "id": "061ce3ac-80a0-43a5-8f94-275468820a79",
              "name": "status",
              "type": "string",
              "value": "={{ String($json.status ?? '') }}"
            },
            {
              "id": "38b7d37a-012e-48ab-8fe4-33a622d606c2",
              "name": "classifications",
              "type": "string",
              "value": "={{ ($json.classifications ?? []).join(', ') }}"
            },
            {
              "id": "ac0e9156-a569-4084-85fb-ef096aa9a8f8",
              "name": "expiration_date",
              "type": "string",
              "value": "={{ String($json.expiration_date ?? '') }}"
            },
            {
              "id": "742719eb-b009-415b-888c-b165265c7f8c",
              "name": "bonded",
              "type": "string",
              "value": "={{ String($json.bonded ?? '') }}"
            },
            {
              "id": "761a3954-7ae2-4a25-850f-5c00029448c3",
              "name": "workers_comp",
              "type": "string",
              "value": "={{ String($json.workers_comp ?? '') }}"
            },
            {
              "id": "493453b5-93b4-490c-8325-a606e5bc929f",
              "name": "liability_insured",
              "type": "string",
              "value": "={{ String($json.liability_insured ?? '') }}"
            },
            {
              "id": "e66fbfe5-149e-4a3c-897e-e581bd95e302",
              "name": "match_confidence",
              "type": "string",
              "value": "={{ String($json.match_confidence ?? '') }}"
            },
            {
              "id": "1ec807e5-5dd8-4f68-8b0f-f0d278bf881b",
              "name": "source_url",
              "type": "string",
              "value": "={{ String($json.source_url ?? '') }}"
            },
            {
              "id": "b04a5bd3-574e-4825-8d15-f61d559982dd",
              "name": "source_as_of",
              "type": "string",
              "value": "={{ String($json.source_as_of ?? '') }}"
            }
          ]
        }
      },
      "id": "f0fa3939-b51d-43e0-83e7-8d109baacf3c",
      "name": "Map verdict fields",
      "type": "n8n-nodes-base.set",
      "position": [
        1100,
        0
      ],
      "typeVersion": 3.4
    },
    {
      "parameters": {
        "columns": {
          "value": {
            "row_number": "={{ $json.row_number }}",
            "verdict": "={{ $json.verdict }}",
            "license_number": "={{ $json.license_number }}",
            "business_name": "={{ $json.business_name }}",
            "dba": "={{ $json.dba }}",
            "status": "={{ $json.status }}",
            "classifications": "={{ $json.classifications }}",
            "expiration_date": "={{ $json.expiration_date }}",
            "bonded": "={{ $json.bonded }}",
            "workers_comp": "={{ $json.workers_comp }}",
            "liability_insured": "={{ $json.liability_insured }}",
            "match_confidence": "={{ $json.match_confidence }}",
            "source_url": "={{ $json.source_url }}",
            "source_as_of": "={{ $json.source_as_of }}"
          },
          "schema": [],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "row_number"
          ]
        },
        "options": {},
        "operation": "update",
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "YOUR_GOOGLE_SHEET_ID"
        }
      },
      "id": "5ab65e73-e772-4f6d-8345-9406dd00c49f",
      "name": "Write results",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1320,
        0
      ],
      "typeVersion": 4.5,
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "REPLACE_WITH_YOUR_CREDENTIAL",
          "name": "Google Sheets account"
        }
      }
    }
  ],
  "connections": {
    "Run checks": {
      "main": [
        [
          {
            "node": "Read rows",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read rows": {
      "main": [
        [
          {
            "node": "Build batch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build batch": {
      "main": [
        [
          {
            "node": "Run actor (run-sync)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Run actor (run-sync)": {
      "main": [
        [
          {
            "node": "One item per result",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "One item per result": {
      "main": [
        [
          {
            "node": "Map verdict fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Map verdict fields": {
      "main": [
        [
          {
            "node": "Write results",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "meta": {
    "templateCredsSetupCompleted": false
  }
}
