{
  "name": "Business Entity Check (Apify pelicanlabs/business-entity-check) -> Google Sheets",
  "nodes": [
    {
      "parameters": {
        "content": "## Business Entity Check on Apify (pelicanlabs/business-entity-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) `Company Name`, `State` and these result columns: `status`, `matched`, `entity_name`, `entity_id`, `entity_type`, `formation_date`, `age_years`, `registered_agent`, `principal_address`, `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.004 per matched business (unmatched 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": "8a7356de-fe76-4b51-88df-d2c6b3835d8e",
      "name": "How to set up",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -620,
        -260
      ],
      "typeVersion": 1
    },
    {
      "parameters": {},
      "id": "f612cbe8-0410-4d86-8dac-b2e97656942d",
      "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": "91205dcf-f344-465b-8a2b-f6c1d702f70d",
      "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 NAME_COLUMN = 'Company Name';   // column with the business name\nconst STATE_COLUMN = 'State';         // CO, CT, NY, OR or TX (full names work too)\nconst RESULT_COLUMN = 'status';      // 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[NAME_COLUMN] ?? '').trim() !== '' && String(r[RESULT_COLUMN] ?? '').trim() === '')\n  .slice(0, MAX_ROWS);\nif (!rows.length) return [];\nconst queries = rows.map((r) => ({ state: String(r[STATE_COLUMN] ?? '').trim(), entity_name: String(r[NAME_COLUMN]).trim() }));\nreturn [{ json: { row_numbers: rows.map((r) => r.row_number), body: { queries } } }];"
      },
      "id": "511dde68-5656-4b27-89c1-6f5501999ea7",
      "name": "Build batch",
      "type": "n8n-nodes-base.code",
      "position": [
        440,
        0
      ],
      "typeVersion": 2
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.apify.com/v2/acts/pelicanlabs~business-entity-check/run-sync-get-dataset-items",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "memory",
              "value": "256"
            },
            {
              "name": "timeout",
              "value": "280"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify($json.body) }}",
        "options": {
          "timeout": 300000,
          "response": {
            "response": {
              "fullResponse": true
            }
          }
        }
      },
      "id": "fc807211-458b-4229-855b-31d78aa9ce8f",
      "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": "f72bc0e5-cc2f-4796-8c83-d91cbd2aaf2e",
      "name": "One item per result",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        880,
        0
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "ca2070e3-01be-4661-82d0-e3693f6f8b42",
              "name": "row_number",
              "type": "number",
              "value": "={{ $('Build batch').first().json.row_numbers[Number(String($json.input_ref).match(/\\d+/)[0])] }}"
            },
            {
              "id": "a58986d6-3334-4447-88ec-87fee57c70a4",
              "name": "status",
              "type": "string",
              "value": "={{ $json.status ?? ('invalid: ' + ($json.error ?? 'no result')) }}"
            },
            {
              "id": "e22390df-dad3-4da1-86e6-e3d54588016a",
              "name": "matched",
              "type": "string",
              "value": "={{ String($json.matched ?? '') }}"
            },
            {
              "id": "06e87ab2-f68f-48b8-8242-547fdb804d64",
              "name": "entity_name",
              "type": "string",
              "value": "={{ String($json.entity_name ?? '') }}"
            },
            {
              "id": "1d47b8dc-730a-465c-84c2-0c50f1ebf487",
              "name": "entity_id",
              "type": "string",
              "value": "={{ String($json.entity_id ?? '') }}"
            },
            {
              "id": "0571d592-0d3b-4cdc-8a8f-46bf221a0aff",
              "name": "entity_type",
              "type": "string",
              "value": "={{ String($json.entity_type ?? '') }}"
            },
            {
              "id": "7168b79f-8535-42f2-87d3-53b0bf7fe5fd",
              "name": "formation_date",
              "type": "string",
              "value": "={{ String($json.formation_date ?? '') }}"
            },
            {
              "id": "4fe47e34-99d8-4b0b-8d37-5e07eac0f0e7",
              "name": "age_years",
              "type": "string",
              "value": "={{ String($json.age_years ?? '') }}"
            },
            {
              "id": "89ce4110-9ccf-44e5-8882-988a705dff34",
              "name": "registered_agent",
              "type": "string",
              "value": "={{ String($json.registered_agent ?? '') }}"
            },
            {
              "id": "6dda4e07-9e9e-4dd0-8d09-4b56e893ea88",
              "name": "principal_address",
              "type": "string",
              "value": "={{ $json.principal_address ? [$json.principal_address.city, $json.principal_address.state, $json.principal_address.zip].filter(Boolean).join(', ') : '' }}"
            },
            {
              "id": "8d4a727f-6ace-48f2-8fe1-e34d3d64b4a4",
              "name": "match_confidence",
              "type": "string",
              "value": "={{ String($json.match_confidence ?? '') }}"
            },
            {
              "id": "f5ed1697-3a19-4ee6-879c-8347b9bf68ea",
              "name": "source_url",
              "type": "string",
              "value": "={{ String($json.source_url ?? '') }}"
            },
            {
              "id": "a04d513c-a724-459d-8635-5114cd09546a",
              "name": "source_as_of",
              "type": "string",
              "value": "={{ String($json.source_as_of ?? '') }}"
            }
          ]
        }
      },
      "id": "bf9ed6de-c218-4713-88f6-84d8452c0111",
      "name": "Map verdict fields",
      "type": "n8n-nodes-base.set",
      "position": [
        1100,
        0
      ],
      "typeVersion": 3.4
    },
    {
      "parameters": {
        "columns": {
          "value": {
            "row_number": "={{ $json.row_number }}",
            "status": "={{ $json.status }}",
            "matched": "={{ $json.matched }}",
            "entity_name": "={{ $json.entity_name }}",
            "entity_id": "={{ $json.entity_id }}",
            "entity_type": "={{ $json.entity_type }}",
            "formation_date": "={{ $json.formation_date }}",
            "age_years": "={{ $json.age_years }}",
            "registered_agent": "={{ $json.registered_agent }}",
            "principal_address": "={{ $json.principal_address }}",
            "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": "d41c1dab-e992-4284-8df5-43e5232ea1fc",
      "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
  }
}
