{
  "name": "Deal Stage Change Alert — HubSpot → Slack",
  "nodes": [
    {
      "parameters": {
        "eventsUi": {
          "eventValues": [
            {
              "name": "deal.propertyChange",
              "value": "dealstage"
            }
          ]
        }
      },
      "id": "hubspot-trigger",
      "name": "HubSpot Trigger",
      "type": "n8n-nodes-base.hubspotTrigger",
      "typeVersion": 1,
      "position": [0, 0],
      "webhookId": "hubspot-deal-stage",
      "credentials": {
        "hubspotDeveloperApi": {
          "id": "credential-id",
          "name": "HubSpot Developer API"
        }
      }
    },
    {
      "parameters": {
        "method": "GET",
        "url": "=https://api.hubapi.com/crm/v3/objects/deals/{{ $json.objectId }}",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "hubspotApi",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "properties",
              "value": "dealname,amount,dealstage,pipeline,hubspot_owner_id,closedate"
            }
          ]
        },
        "options": {}
      },
      "id": "fetch-deal",
      "name": "Fetch Deal",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [220, 0],
      "credentials": {
        "hubspotApi": {
          "id": "credential-id",
          "name": "HubSpot API"
        }
      }
    },
    {
      "parameters": {
        "method": "GET",
        "url": "https://api.hubapi.com/crm/v3/pipelines/deals",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "hubspotApi",
        "options": {}
      },
      "id": "fetch-pipelines",
      "name": "Fetch Pipelines",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [220, 200],
      "credentials": {
        "hubspotApi": {
          "id": "credential-id",
          "name": "HubSpot API"
        }
      }
    },
    {
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "const pipelines = $('Fetch Pipelines').first().json.results;\nconst deal = $('Fetch Deal').first().json;\n\nlet stageName = deal.properties.dealstage;\nfor (const pipeline of pipelines) {\n  const stage = pipeline.stages.find(s => s.id === deal.properties.dealstage);\n  if (stage) {\n    stageName = stage.label;\n    break;\n  }\n}\n\nreturn [{\n  json: {\n    dealName: deal.properties.dealname,\n    amount: parseFloat(deal.properties.amount || '0'),\n    stageName,\n    ownerId: deal.properties.hubspot_owner_id,\n    dealId: deal.id,\n  }\n}];"
      },
      "id": "resolve-stage",
      "name": "Resolve Stage Name",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [440, 0]
    },
    {
      "parameters": {
        "select": "channel",
        "channelId": {
          "__rl": true,
          "value": "sales-pipeline",
          "mode": "name"
        },
        "messageType": "block",
        "blocksUi": "={\n  \"blocks\": [\n    {\n      \"type\": \"section\",\n      \"text\": {\n        \"type\": \"mrkdwn\",\n        \"text\": \":arrows_counterclockwise: *Deal Stage Changed*\\n*\" + $json.dealName + \"* moved to *\" + $json.stageName + \"*\\nAmount: $\" + $json.amount.toLocaleString()\n      }\n    },\n    {\n      \"type\": \"context\",\n      \"elements\": [\n        {\n          \"type\": \"mrkdwn\",\n          \"text\": \"<https://app.hubspot.com/contacts/YOUR_PORTAL_ID/deal/\" + $json.dealId + \"|View in HubSpot>\"\n        }\n      ]\n    }\n  ]\n}",
        "otherOptions": {
          "unfurl_links": false
        }
      },
      "id": "post-to-slack",
      "name": "Post to Slack",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2.3,
      "position": [660, 0],
      "credentials": {
        "slackApi": {
          "id": "credential-id",
          "name": "Slack API"
        }
      }
    }
  ],
  "connections": {
    "HubSpot Trigger": {
      "main": [
        [
          {
            "node": "Fetch Deal",
            "type": "main",
            "index": 0
          },
          {
            "node": "Fetch Pipelines",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Deal": {
      "main": [
        [
          {
            "node": "Resolve Stage Name",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Pipelines": {
      "main": [
        [
          {
            "node": "Resolve Stage Name",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Resolve Stage Name": {
      "main": [
        [
          {
            "node": "Post to Slack",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": null,
  "tags": [],
  "triggerCount": 0,
  "active": false,
  "meta": {
    "instanceId": "",
    "templateId": "revi-deal-stage-alert"
  }
}
