{
  "id": "KIIS9aCyWhg38JKK",
  "name": "Reassigned Numbers Database",
  "tags": [],
  "nodes": [
    {
      "id": "32261725-9e19-4ebc-ba66-668ac7f71ca0",
      "name": "RND Search Form",
      "type": "n8n-nodes-base.formTrigger",
      "position": [
        688,
        544
      ],
      "parameters": {
        "options": {
          "buttonLabel": "Check Reassigned Status"
        },
        "formTitle": "Reassigned Number Check",
        "formFields": {
          "values": [
            {
              "fieldLabel": "phone",
              "placeholder": "e.g. 2127731234 (10 digits)",
              "requiredField": true
            },
            {
              "fieldType": "date",
              "fieldLabel": "date",
              "requiredField": true
            }
          ]
        },
        "responseMode": "lastNode",
        "formDescription": "Check whether a phone number has been reassigned since a consent/contact reference date. Both fields are required."
      },
      "typeVersion": 2.2
    },
    {
      "id": "64f63ffa-7888-4450-9976-cf3925cf3d7f",
      "name": "Set Search Input",
      "type": "n8n-nodes-base.set",
      "position": [
        976,
        544
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "c1",
              "name": "submittedPhone",
              "type": "string",
              "value": "={{ $json.phone }}"
            },
            {
              "id": "c2",
              "name": "cleanedPhone",
              "type": "string",
              "value": "={{ ($json.phone || '').toString().replace(/[^0-9]/g, '') }}"
            },
            {
              "id": "c3",
              "name": "date",
              "type": "string",
              "value": "={{ ($json.date || '').toString().slice(0, 10) }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "03264bb9-978e-4a23-afce-724220ea8363",
      "name": "Reassigned Numbers Data HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1360,
        544
      ],
      "parameters": {
        "url": "https://data.searchbug.com/api/search.aspx",
        "method": "POST",
        "options": {},
        "jsonBody": "=[\n  {\n    \"phone\": \"{{ $json.cleanedPhone }}\",\n    \"date\": \"{{ $json.date }}\"\n  }\n]",
        "sendBody": true,
        "sendHeaders": true,
        "specifyBody": "json",
        "headerParameters": {
          "parameters": [
            {
              "name": "CO_CODE"
            },
            {
              "name": "PASS"
            },
            {
              "name": "TYPE",
              "value": "api_rnd"
            },
            {
              "name": "FORMAT",
              "value": "JSON"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        }
      },
      "typeVersion": 4.4,
      "continueOnFail": true
    },
    {
      "id": "22f007e4-fdfa-4190-bf26-468776327265",
      "name": "Parse Result",
      "type": "n8n-nodes-base.set",
      "position": [
        1632,
        544
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "p1",
              "name": "submittedPhone",
              "type": "string",
              "value": "={{ $('Set Search Input').item.json.submittedPhone }}"
            },
            {
              "id": "p2",
              "name": "cleanedPhone",
              "type": "string",
              "value": "={{ $('Set Search Input').item.json.cleanedPhone }}"
            },
            {
              "id": "p3",
              "name": "consentDate",
              "type": "string",
              "value": "={{ $('Set Search Input').item.json.date }}"
            },
            {
              "id": "p4",
              "name": "reassignedStatus",
              "type": "string",
              "value": "={{ $json.results?.[0]?.reassigned ?? 'ERROR' }}"
            },
            {
              "id": "p5",
              "name": "apiPhone",
              "type": "string",
              "value": "={{ $json.results?.[0]?.phone ?? '' }}"
            },
            {
              "id": "p6",
              "name": "apiDate",
              "type": "string",
              "value": "={{ $json.results?.[0]?.date ?? '' }}"
            },
            {
              "id": "p7",
              "name": "statusMeaning",
              "type": "string",
              "value": "={{ $json.results?.[0]?.reassigned === 'YES' ? 'Phone number was reassigned after the provided date. Do not contact.' : $json.results?.[0]?.reassigned === 'NO' ? 'Phone number was not reassigned or permanently disconnected since the provided date.' : $json.results?.[0]?.reassigned === 'NO_DATA' ? 'No carrier data available since FCC reporting started.' : 'API or input error.' }}"
            },
            {
              "id": "p8",
              "name": "rawResponse",
              "type": "string",
              "value": "={{ JSON.stringify($json) }}"
            },
            {
              "id": "p9",
              "name": "createdAt",
              "type": "string",
              "value": "={{ $now.toISO() }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "2555e9ef-e0b9-4be7-ba57-8b3fbdc5e82a",
      "name": "Append Row to Sheet",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        2128,
        544
      ],
      "parameters": {
        "columns": {
          "value": {
            "API Date": "={{ $json.apiDate }}",
            "API Phone": "={{ $json.apiPhone }}",
            "Created At": "={{ $json.createdAt }}",
            "Consent Date": "={{ $json.consentDate }}",
            "Cleaned Phone": "={{ $json.cleanedPhone }}",
            "Status Meaning": "={{ $json.statusMeaning }}",
            "Submitted Phone": "={{ $json.submittedPhone }}",
            "Raw API Response": "={{ $json.rawResponse }}",
            "Reassigned Status": "={{ $json.reassignedStatus }}"
          },
          "schema": [
            {
              "id": "Submitted Phone",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Submitted Phone",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Cleaned Phone",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Cleaned Phone",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Consent Date",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Consent Date",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Reassigned Status",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Reassigned Status",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "API Phone",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "API Phone",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "API Date",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "API Date",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Status Meaning",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Status Meaning",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Raw API Response",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Raw API Response",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Created At",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Created At",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "Reassigned Numbers"
        },
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "1XkeYRHD2qs145Ashc0qrisUDxDkrWu1WlhddaYyB8N8"
        }
      },
      "typeVersion": 4.5
    },
    {
      "id": "215f827d-87b4-4721-8574-f5499906d634",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        0,
        -16
      ],
      "parameters": {
        "color": "#FEEA87",
        "width": 552,
        "height": 872,
        "content": "## \ud83d\udcde Reassigned Numbers Check \u2014 Searchbug (api_rnd)\n\nCheck whether a phone number was reassigned to a new person since a consent / last-contact date \u2014 helping you stay TCPA-compliant before you call or text.\n\n### How it works\n1. Enter a phone number and a consent date in the form.\n2. The number is cleaned to digits; the date to YYYY-MM-DD.\n3. Searchbug's Reassigned Numbers Database checks if the number changed hands since that date.\n4. The result (YES / NO / NO_DATA) is turned into plain English and saved to your Google Sheet.\n\n### How to set up\n- [ ] Add your Searchbug CO_CODE + PASS in the HTTP Request (Headers)\n- [ ] Connect your OWN Google Sheets account in the Save node\n- [ ] Change the Document to your own spreadsheet + tab\n- [ ] Add the 9 headers below to row 1 of your tab\n- [ ] Activate and share the form link\n\n### Sheet headers (row 1)\nSubmitted Phone \u00b7 Cleaned Phone \u00b7 Consent Date \u00b7 Reassigned Status \u00b7 API Phone \u00b7 API Date \u00b7 Status Meaning \u00b7 Raw API Response \u00b7 Created At\n\n### Customization\n- Add a Slack/email alert after Save for YES (do-not-contact) results.\n- Adjust which statuses count as \"safe\" in the Parse Result node."
      },
      "typeVersion": 1
    },
    {
      "id": "43b3620a-a253-4bc6-aecf-89c20c7db9b2",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        608,
        336
      ],
      "parameters": {
        "color": 7,
        "width": 600,
        "height": 400,
        "content": "## 1. Collect the number\n\nEnter a phone number and consent date. The workflow cleans both values before sending them to the API."
      },
      "typeVersion": 1
    },
    {
      "id": "6c97eb6d-67c0-4836-925d-d559a79d0fa8",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1280,
        336
      ],
      "parameters": {
        "color": 7,
        "width": 600,
        "height": 400,
        "content": "## 2. Check with Searchbug\n\nThe API checks the Reassigned Numbers Database. The response is then converted into a clear status and explanation."
      },
      "typeVersion": 1
    },
    {
      "id": "131b43cf-cb0d-46e5-897f-5affeecc2d4b",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1968,
        336
      ],
      "parameters": {
        "color": "#FCD9DD",
        "width": 520,
        "height": 400,
        "content": "## 3. Save to Google Sheets\n\nConnect your own Google Sheets credential and select your spreadsheet and tab. Add the nine headers listed in the overview note."
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "binaryMode": "separate",
    "executionOrder": "v1"
  },
  "versionId": "ef8a8587-9b7e-48e7-b8ac-7de8d7898997",
  "nodeGroups": [],
  "connections": {
    "Parse Result": {
      "main": [
        [
          {
            "node": "Append Row to Sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "RND Search Form": {
      "main": [
        [
          {
            "node": "Set Search Input",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Search Input": {
      "main": [
        [
          {
            "node": "Reassigned Numbers Data HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Reassigned Numbers Data HTTP Request": {
      "main": [
        [
          {
            "node": "Parse Result",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}