{
  "name": "Sync Local Falcon rankings to Pipedrive deals",
  "nodes": [
    {
      "parameters": {
        "content": "## Sync Local Falcon Rankings to Pipedrive Deals\n\n**Who is this for:** SEO agencies using Pipedrive CRM who want to automatically update deal records with client ranking data for better pipeline management.\n\n**What this workflow does:**\n1. Fetches recent scan reports from Local Falcon\n2. Matches locations to Pipedrive deals using a custom field (place_id)\n3. Updates deal records with latest avg_rank and scan date\n4. Adds activity notes for significant ranking changes\n\n**How to set up:**\n1. Add your Local Falcon API credentials (get your key at https://www.localfalcon.com/api/credentials)\n2. Add your Pipedrive API credentials\n3. Create a custom field in Pipedrive: `local_falcon_place_id`\n4. Add place_id values to your deal records\n5. Activate the workflow\n\n**Requirements:**\n- Local Falcon account with API access\n- Pipedrive account with API access\n- Custom fields configured in Pipedrive\n\n**How to customize:**\n- Sync to Person or Organization records instead\n- Trigger deal stage changes based on ranking improvements\n- Add Slack notifications for ranking milestones",
        "height": 560,
        "width": 460,
        "color": 5
      },
      "id": "sticky-main",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        100,
        -200
      ]
    },
    {
      "parameters": {
        "content": "### Step 1: Schedule\nRuns daily to keep CRM updated.",
        "height": 100,
        "width": 200
      },
      "id": "sticky-step1",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        40,
        680
      ]
    },
    {
      "parameters": {
        "content": "### Step 2: Get Reports\nFetches latest scan data.",
        "height": 100,
        "width": 200
      },
      "id": "sticky-step2",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        300,
        680
      ]
    },
    {
      "parameters": {
        "content": "### Step 3: Transform\nFormats data for Pipedrive.",
        "height": 100,
        "width": 200
      },
      "id": "sticky-step3",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        560,
        680
      ]
    },
    {
      "parameters": {
        "content": "### Step 4: Find Deal\nLooks up deal by place_id.",
        "height": 100,
        "width": 200
      },
      "id": "sticky-step4",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        820,
        680
      ]
    },
    {
      "parameters": {
        "content": "### Step 5: Update Deal\nSyncs ranking data to deal.",
        "height": 100,
        "width": 200
      },
      "id": "sticky-step5",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        1080,
        680
      ]
    },
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "days",
              "triggerAtHour": 7
            }
          ]
        }
      },
      "id": "schedule",
      "name": "Every Day 7am",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        140,
        460
      ]
    },
    {
      "parameters": {
        "resource": "scan",
        "operation": "listReports",
        "additionalFields": {
          "limit": 50
        }
      },
      "id": "get-reports",
      "name": "Get Scan Reports",
      "type": "@local-falcon/n8n-nodes-localfalcon.localFalcon",
      "typeVersion": 1,
      "position": [
        400,
        460
      ],
      "credentials": {
        "localFalconApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "const reports = $input.first().json.reports || [];\n\nreturn reports.map(report => ({\n  json: {\n    place_id: report.place_id,\n    location_name: report.location_name,\n    keyword: report.keyword,\n    avg_rank: report.avg_rank,\n    platform: report.platform,\n    scan_date: report.scan_date,\n    rank_change: report.rank_change || 0\n  }\n}));"
      },
      "id": "transform",
      "name": "Transform Data",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        660,
        460
      ]
    },
    {
      "parameters": {
        "resource": "deal",
        "operation": "search",
        "term": "={{ $json.place_id }}",
        "additionalFields": {
          "fields": "custom_fields"
        }
      },
      "id": "find-deal",
      "name": "Find Pipedrive Deal",
      "type": "n8n-nodes-base.pipedrive",
      "typeVersion": 1,
      "position": [
        920,
        460
      ],
      "credentials": {
        "pipedriveApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "resource": "deal",
        "operation": "update",
        "dealId": "={{ $json.data[0].id }}",
        "updateFields": {
          "customProperties": {
            "customProperty": [
              {
                "name": "local_falcon_avg_rank",
                "value": "={{ $('Transform Data').item.json.avg_rank }}"
              },
              {
                "name": "local_falcon_last_scan",
                "value": "={{ $('Transform Data').item.json.scan_date }}"
              }
            ]
          }
        }
      },
      "id": "update-deal",
      "name": "Update Deal Rankings",
      "type": "n8n-nodes-base.pipedrive",
      "typeVersion": 1,
      "position": [
        1180,
        460
      ],
      "credentials": {
        "pipedriveApi": {
          "name": "<your credential>"
        }
      }
    }
  ],
  "connections": {
    "Every Day 7am": {
      "main": [
        [
          {
            "node": "Get Scan Reports",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Scan Reports": {
      "main": [
        [
          {
            "node": "Transform Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Transform Data": {
      "main": [
        [
          {
            "node": "Find Pipedrive Deal",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Find Pipedrive Deal": {
      "main": [
        [
          {
            "node": "Update Deal Rankings",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "meta": {
    "templateCredsSetupCompleted": true
  }
}