{
  "name": "Carrier Risk Check (Apify pelicanlabs/carrier-risk-check) -> Google Sheets",
  "nodes": [
    {
      "parameters": {
        "content": "## Carrier Risk Check on Apify (pelicanlabs/carrier-risk-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) `MC or USDOT` and these result columns: `verdict`, `reason_codes`, `legal_name`, `usdot`, `mc_numbers`, `authority_status`, `authority_age_days`, `bipd_on_file_usd`, `safety_rating`, `vehicle_oos_rate`, `driver_oos_rate`, `crashes_24m`, `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 check (rows with an invalid number 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": "7f44ef90-c82c-4275-86f8-b52448b6d426",
      "name": "How to set up",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -620,
        -260
      ],
      "typeVersion": 1
    },
    {
      "parameters": {},
      "id": "0a32cbc2-e47e-4603-8c3d-4331d3374a7c",
      "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": "7733ac23-b941-474a-8006-34a2d76897d8",
      "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 = 'MC or USDOT'; // 3262418, USDOT 3262418, MC-1409700, MX-..., FF-...\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) => String(r[VALUE_COLUMN]).trim());\nreturn [{ json: { row_numbers: rows.map((r) => r.row_number), body: { carriers: queries, maxItems: queries.length } } }];"
      },
      "id": "aaad0623-781f-45a0-8cb0-1afc56b506bc",
      "name": "Build batch",
      "type": "n8n-nodes-base.code",
      "position": [
        440,
        0
      ],
      "typeVersion": 2
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.apify.com/v2/acts/pelicanlabs~carrier-risk-check/run-sync-get-dataset-items",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "memory",
              "value": "2048"
            },
            {
              "name": "timeout",
              "value": "280"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify($json.body) }}",
        "options": {
          "timeout": 300000,
          "response": {
            "response": {
              "fullResponse": true
            }
          }
        }
      },
      "id": "7c759151-85fe-440f-8b53-185586867669",
      "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": "c3768f59-e0bf-4af4-8e19-a9894d97eb4a",
      "name": "One item per result",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        880,
        0
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "50c4fe8d-d354-4e90-8485-4686ca875a34",
              "name": "row_number",
              "type": "number",
              "value": "={{ $('Build batch').first().json.row_numbers[$itemIndex] }}"
            },
            {
              "id": "b2cc802a-4dff-42fe-8f66-befe7aefd63d",
              "name": "verdict",
              "type": "string",
              "value": "={{ $json.verdict ?? ('invalid: ' + ($json.error ?? 'no result')) }}"
            },
            {
              "id": "10be667e-0b95-4b31-80d1-a97223b388d7",
              "name": "reason_codes",
              "type": "string",
              "value": "={{ Array.isArray($json.reason_codes) ? $json.reason_codes.join(', ') : String($json.reason_codes ?? '') }}"
            },
            {
              "id": "71baeb67-e568-45ed-8ed3-5e5b2340d6e0",
              "name": "legal_name",
              "type": "string",
              "value": "={{ String($json.legal_name ?? '') }}"
            },
            {
              "id": "d329ef01-6f9c-40eb-8622-322bfaf636a0",
              "name": "usdot",
              "type": "string",
              "value": "={{ String($json.usdot ?? '') }}"
            },
            {
              "id": "61b92aab-b5ce-4985-8d20-c12ccf9921f2",
              "name": "mc_numbers",
              "type": "string",
              "value": "={{ ($json.mc_numbers ?? []).join(', ') }}"
            },
            {
              "id": "3e8a5acd-d5aa-4315-88dc-d878da912f0f",
              "name": "authority_status",
              "type": "string",
              "value": "={{ String($json.authority_status ?? '') }}"
            },
            {
              "id": "573dde8e-5947-437b-8ea7-7df85e0b489e",
              "name": "authority_age_days",
              "type": "string",
              "value": "={{ String($json.authority_age_days ?? '') }}"
            },
            {
              "id": "c5b099c5-277f-458d-8216-deed883100c9",
              "name": "bipd_on_file_usd",
              "type": "string",
              "value": "={{ String($json.bipd_on_file_usd ?? '') }}"
            },
            {
              "id": "39bd9a26-27b6-4bd1-88d6-f390041d06ae",
              "name": "safety_rating",
              "type": "string",
              "value": "={{ String($json.safety_rating ?? '') }}"
            },
            {
              "id": "a61bf091-d1e1-4981-81a7-89fa17a19ca9",
              "name": "vehicle_oos_rate",
              "type": "string",
              "value": "={{ String($json.vehicle_oos_rate ?? '') }}"
            },
            {
              "id": "751cd628-3c32-49f5-8825-70d7b4fefb77",
              "name": "driver_oos_rate",
              "type": "string",
              "value": "={{ String($json.driver_oos_rate ?? '') }}"
            },
            {
              "id": "c42ce4dc-a375-4890-897e-1c4c8ab42b19",
              "name": "crashes_24m",
              "type": "string",
              "value": "={{ String($json.crashes_24m ?? '') }}"
            },
            {
              "id": "4ef78b8b-25af-4a64-8f38-d456a4a225ea",
              "name": "source_url",
              "type": "string",
              "value": "={{ typeof $json.source_url === 'string' ? $json.source_url : '' }}"
            },
            {
              "id": "0797689e-e9a7-4231-8744-38e1bcc50e91",
              "name": "source_as_of",
              "type": "string",
              "value": "={{ typeof $json.source_as_of === 'string' ? $json.source_as_of : '' }}"
            }
          ]
        }
      },
      "id": "10fd93bd-7cd8-4790-8b37-e00b10fc4746",
      "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 }}",
            "reason_codes": "={{ $json.reason_codes }}",
            "legal_name": "={{ $json.legal_name }}",
            "usdot": "={{ $json.usdot }}",
            "mc_numbers": "={{ $json.mc_numbers }}",
            "authority_status": "={{ $json.authority_status }}",
            "authority_age_days": "={{ $json.authority_age_days }}",
            "bipd_on_file_usd": "={{ $json.bipd_on_file_usd }}",
            "safety_rating": "={{ $json.safety_rating }}",
            "vehicle_oos_rate": "={{ $json.vehicle_oos_rate }}",
            "driver_oos_rate": "={{ $json.driver_oos_rate }}",
            "crashes_24m": "={{ $json.crashes_24m }}",
            "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": "23373eb5-9104-45f1-8ccb-3615ee41ae58",
      "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
  }
}
