{
  "name": "Sales-to-CS Handoff — HubSpot → Slack",
  "nodes": [
    {
      "parameters": {
        "eventsUi": {
          "eventValues": [
            {
              "name": "deal.propertyChange",
              "property": "dealstage"
            }
          ]
        }
      },
      "id": "hubspot-trigger",
      "name": "HubSpot Trigger",
      "type": "n8n-nodes-base.hubspotTrigger",
      "typeVersion": 1,
      "position": [0, 0],
      "webhookId": "hubspot-trigger-id",
      "credentials": {
        "hubspotApi": {
          "id": "credential-id",
          "name": "HubSpot API"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": ""
          },
          "conditions": [
            {
              "leftValue": "={{ $json.properties.dealstage.value }}",
              "rightValue": "closedwon",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        }
      },
      "id": "filter-closed-won",
      "name": "Is Closed Won?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [220, 0]
    },
    {
      "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,hubspot_owner_id,closedate,hs_num_associated_contacts,contract_length,description"
            },
            {
              "name": "associations",
              "value": "contacts"
            }
          ]
        },
        "options": {}
      },
      "id": "fetch-deal",
      "name": "Fetch Deal",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [440, 0],
      "credentials": {
        "hubspotApi": {
          "id": "credential-id",
          "name": "HubSpot API"
        }
      }
    },
    {
      "parameters": {
        "method": "GET",
        "url": "=https://api.hubapi.com/crm/v3/objects/contacts/{{ $json.associations.contacts.results[0].id }}",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "hubspotApi",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "properties",
              "value": "firstname,lastname,email,phone,jobtitle,company"
            }
          ]
        },
        "options": {}
      },
      "id": "fetch-contact",
      "name": "Fetch Contact",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [660, 0],
      "credentials": {
        "hubspotApi": {
          "id": "credential-id",
          "name": "HubSpot API"
        }
      }
    },
    {
      "parameters": {
        "method": "GET",
        "url": "=https://api.hubapi.com/crm/v3/owners/{{ $('Fetch Deal').item.json.properties.hubspot_owner_id }}",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "hubspotApi",
        "options": {}
      },
      "id": "fetch-owner",
      "name": "Fetch Owner",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [880, 0],
      "credentials": {
        "hubspotApi": {
          "id": "credential-id",
          "name": "HubSpot API"
        }
      }
    },
    {
      "parameters": {
        "select": "channel",
        "channelId": {
          "__rl": true,
          "value": "cs-handoffs",
          "mode": "name"
        },
        "messageType": "block",
        "blocksUi": "={\n  \"blocks\": [\n    {\n      \"type\": \"header\",\n      \"text\": {\n        \"type\": \"plain_text\",\n        \"text\": \"🎉 New Closed-Won Deal — CS Handoff\"\n      }\n    },\n    {\n      \"type\": \"section\",\n      \"fields\": [\n        { \"type\": \"mrkdwn\", \"text\": \"*Deal*\\n\" + $('Fetch Deal').item.json.properties.dealname },\n        { \"type\": \"mrkdwn\", \"text\": \"*Value*\\n$\" + parseFloat($('Fetch Deal').item.json.properties.amount || '0').toLocaleString() },\n        { \"type\": \"mrkdwn\", \"text\": \"*Sales Rep*\\n\" + $('Fetch Owner').item.json.firstName + \" \" + $('Fetch Owner').item.json.lastName },\n        { \"type\": \"mrkdwn\", \"text\": \"*Close Date*\\n\" + $('Fetch Deal').item.json.properties.closedate.split('T')[0] }\n      ]\n    },\n    { \"type\": \"divider\" },\n    {\n      \"type\": \"section\",\n      \"text\": {\n        \"type\": \"mrkdwn\",\n        \"text\": \"*Primary Contact*\\n\" + $('Fetch Contact').item.json.properties.firstname + \" \" + $('Fetch Contact').item.json.properties.lastname + \" (\" + ($('Fetch Contact').item.json.properties.jobtitle || 'No title') + \")\\n📧 \" + $('Fetch Contact').item.json.properties.email + \"\\n📞 \" + ($('Fetch Contact').item.json.properties.phone || 'No phone')\n      }\n    },\n    {\n      \"type\": \"section\",\n      \"text\": {\n        \"type\": \"mrkdwn\",\n        \"text\": \"*Contract Length*\\n\" + ($('Fetch Deal').item.json.properties.contract_length || 'Not specified')\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": [1100, 0],
      "credentials": {
        "slackApi": {
          "id": "credential-id",
          "name": "Slack API"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.hubapi.com/crm/v3/objects/tasks",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "hubspotApi",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"properties\": {\n    \"hs_task_subject\": \"Onboarding: \" + $('Fetch Deal').item.json.properties.dealname,\n    \"hs_task_body\": \"New closed-won deal ready for CS onboarding.\\n\\nDeal: \" + $('Fetch Deal').item.json.properties.dealname + \"\\nValue: $\" + parseFloat($('Fetch Deal').item.json.properties.amount || '0').toLocaleString() + \"\\nSales Rep: \" + $('Fetch Owner').item.json.firstName + \" \" + $('Fetch Owner').item.json.lastName + \"\\nContact: \" + $('Fetch Contact').item.json.properties.email,\n    \"hs_task_status\": \"NOT_STARTED\",\n    \"hs_task_priority\": \"HIGH\",\n    \"hubspot_owner_id\": \"CS_REP_OWNER_ID\",\n    \"hs_timestamp\": \"\" + new Date().toISOString()\n  },\n  \"associations\": [\n    {\n      \"to\": { \"id\": \"\" + $('Fetch Deal').item.json.id },\n      \"types\": [{ \"associationCategory\": \"HUBSPOT_DEFINED\", \"associationTypeId\": 204 }]\n    }\n  ]\n}",
        "options": {}
      },
      "id": "create-task",
      "name": "Create CS Task",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [1320, 0],
      "credentials": {
        "hubspotApi": {
          "id": "credential-id",
          "name": "HubSpot API"
        }
      }
    }
  ],
  "connections": {
    "HubSpot Trigger": {
      "main": [
        [
          {
            "node": "Is Closed Won?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Is Closed Won?": {
      "main": [
        [
          {
            "node": "Fetch Deal",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Deal": {
      "main": [
        [
          {
            "node": "Fetch Contact",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Contact": {
      "main": [
        [
          {
            "node": "Fetch Owner",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Owner": {
      "main": [
        [
          {
            "node": "Post to Slack",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Post to Slack": {
      "main": [
        [
          {
            "node": "Create CS Task",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": null,
  "tags": [],
  "triggerCount": 0,
  "active": false,
  "meta": {
    "instanceId": "",
    "templateId": "revi-cs-handoff"
  }
}