{
  "name": "S2D recipe - hubspot-deal-quote-pdf",
  "nodes": [
    {
      "id": "c1000000-0000-4000-8000-000000000001",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -760,
        -400
      ],
      "parameters": {
        "width": 600,
        "height": 340,
        "content": "## Quote PDF from a HubSpot deal\nWhen a deal moves to your quote stage, the workflow reads the deal and its company and starts one SourceToDocs run: a quote from your Google Docs template, saved to Google Drive as a Doc and a PDF. The link is written back to the deal.\n\n**Set up before you activate**\n- Credentials: HubSpot Developer API on the trigger, a HubSpot credential on the three HubSpot nodes, a SourceToDocs API token on the SourceToDocs node\n- SourceToDocs node: your quote document and its data set with the columns Customer, Quote number, Scope, Total, Valid until\n- If node: replace `YOUR_QUOTE_STAGE_ID` with the internal ID of your quote stage\n- Last HubSpot node: `quote_link` is the internal name of the custom deal property Quote link; pick yours if it differs\n\nGuide: https://sourcetodocs.com/automations/hubspot-deal-quote-pdf/"
      }
    },
    {
      "id": "c1000000-0000-4000-8000-000000000002",
      "name": "HubSpot Trigger",
      "type": "n8n-nodes-base.hubspotTrigger",
      "typeVersion": 1,
      "position": [
        -700,
        0
      ],
      "parameters": {
        "eventsUi": {
          "eventValues": [
            {
              "name": "deal.propertyChange",
              "property": "dealstage"
            }
          ]
        },
        "additionalFields": {}
      }
    },
    {
      "id": "c1000000-0000-4000-8000-000000000003",
      "name": "If",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.4,
      "position": [
        -480,
        0
      ],
      "parameters": {
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "c1c00000-0000-4000-8000-000000000001",
              "operator": {
                "name": "filter.operator.equals",
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.propertyValue }}",
              "rightValue": "YOUR_QUOTE_STAGE_ID"
            }
          ]
        },
        "options": {}
      }
    },
    {
      "id": "c1000000-0000-4000-8000-000000000004",
      "name": "Loop Over Items",
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 3,
      "position": [
        -260,
        -20
      ],
      "parameters": {
        "batchSize": 1,
        "options": {}
      }
    },
    {
      "id": "c1000000-0000-4000-8000-000000000005",
      "name": "Get deal",
      "type": "n8n-nodes-base.hubspot",
      "typeVersion": 2.2,
      "position": [
        -20,
        0
      ],
      "parameters": {
        "authentication": "appToken",
        "resource": "deal",
        "operation": "get",
        "dealId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $json.objectId }}"
        },
        "filters": {
          "propertiesCollection": {
            "propertiesValues": {
              "properties": [
                "dealname",
                "amount",
                "closedate"
              ]
            }
          }
        }
      }
    },
    {
      "id": "c1000000-0000-4000-8000-000000000006",
      "name": "Get company",
      "type": "n8n-nodes-base.hubspot",
      "typeVersion": 2.2,
      "position": [
        200,
        0
      ],
      "parameters": {
        "authentication": "appToken",
        "resource": "company",
        "operation": "get",
        "companyId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $json.associations.associatedCompanyIds[0] }}"
        },
        "additionalFields": {}
      }
    },
    {
      "id": "c1000000-0000-4000-8000-000000000007",
      "name": "SourceToDocs",
      "type": "@twovmodules/n8n-nodes-sourcetodocs.sourceToDocs",
      "typeVersion": 1.1,
      "position": [
        420,
        0
      ],
      "parameters": {
        "resource": "document",
        "operation": "generate",
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": ""
        },
        "rowsFrom": "mapped",
        "mappedDataSetId": "",
        "output": "simplified",
        "options": {},
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "Customer": "={{ $json.properties.name.value }}",
            "Quote number": "=Q-{{ $('Loop Over Items').item.json.objectId }}",
            "Scope": "={{ $('Get deal').item.json.properties.dealname.value }}",
            "Total": "={{ $('Get deal').item.json.properties.amount.value }}",
            "Valid until": "={{ $now.plus({ days: 30 }).toFormat('d LLLL yyyy') }}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "Customer",
              "displayName": "Customer",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": false,
              "removed": false
            },
            {
              "id": "Quote number",
              "displayName": "Quote number",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": false,
              "removed": false
            },
            {
              "id": "Scope",
              "displayName": "Scope",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": false,
              "removed": false
            },
            {
              "id": "Total",
              "displayName": "Total",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": false,
              "removed": false
            },
            {
              "id": "Valid until",
              "displayName": "Valid until",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": false,
              "removed": false
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        }
      }
    },
    {
      "id": "c1000000-0000-4000-8000-000000000008",
      "name": "HubSpot",
      "type": "n8n-nodes-base.hubspot",
      "typeVersion": 2.2,
      "position": [
        640,
        0
      ],
      "parameters": {
        "authentication": "appToken",
        "resource": "deal",
        "operation": "update",
        "dealId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $('Loop Over Items').item.json.objectId }}"
        },
        "updateFields": {
          "customPropertiesUi": {
            "customPropertiesValues": [
              {
                "property": "quote_link",
                "value": "={{ $json.file_url }}"
              }
            ]
          }
        }
      }
    }
  ],
  "connections": {
    "HubSpot Trigger": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ],
        []
      ]
    },
    "Loop Over Items": {
      "main": [
        [],
        [
          {
            "node": "Get deal",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get deal": {
      "main": [
        [
          {
            "node": "Get company",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get company": {
      "main": [
        [
          {
            "node": "SourceToDocs",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "SourceToDocs": {
      "main": [
        [
          {
            "node": "HubSpot",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HubSpot": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  }
}
