{
  "name": "S2D recipe - pipedrive-deal-proposal",
  "nodes": [
    {
      "id": "c2000000-0000-4000-8000-000000000001",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -760,
        -400
      ],
      "parameters": {
        "width": 600,
        "height": 340,
        "content": "## Proposal from a Pipedrive deal\nWhen a deal enters your proposal stage, the workflow reads the deal and its organization and starts one SourceToDocs run: a proposal from your Google Docs template, saved to Google Drive as a Doc and a PDF. The links are added to the deal as a note.\n\n**Set up before you activate**\n- Credentials: Pipedrive on the trigger and the three Pipedrive nodes, a SourceToDocs API token on the SourceToDocs node\n- SourceToDocs node: your proposal document and its data set with the columns Client, Project, Scope, Price, Valid until\n- If node: replace `YOUR_STAGE_ID` with the ID of your proposal stage (a number)\n- Scope reads a custom deal field named Scope; change the expression if yours has another name\n\nGuide: https://sourcetodocs.com/automations/pipedrive-deal-proposal/"
      }
    },
    {
      "id": "c2000000-0000-4000-8000-000000000002",
      "name": "Pipedrive Trigger",
      "type": "n8n-nodes-base.pipedriveTrigger",
      "typeVersion": 1.1,
      "position": [
        -700,
        0
      ],
      "parameters": {
        "authentication": "apiToken",
        "incomingAuthentication": "none",
        "action": "change",
        "entity": "deal"
      }
    },
    {
      "id": "c2000000-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": "loose"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "c2c00000-0000-4000-8000-000000000001",
              "operator": {
                "name": "filter.operator.equals",
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.data.stage_id }}",
              "rightValue": "YOUR_STAGE_ID"
            },
            {
              "id": "c2c00000-0000-4000-8000-000000000002",
              "operator": {
                "type": "number",
                "operation": "exists",
                "singleValue": true
              },
              "leftValue": "={{ $json.previous.stage_id }}",
              "rightValue": ""
            }
          ]
        },
        "looseTypeValidation": true,
        "options": {}
      }
    },
    {
      "id": "c2000000-0000-4000-8000-000000000004",
      "name": "Loop Over Items",
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 3,
      "position": [
        -260,
        -20
      ],
      "parameters": {
        "batchSize": 1,
        "options": {}
      }
    },
    {
      "id": "c2000000-0000-4000-8000-000000000005",
      "name": "Get deal",
      "type": "n8n-nodes-base.pipedrive",
      "typeVersion": 2,
      "position": [
        -20,
        0
      ],
      "parameters": {
        "authentication": "apiToken",
        "resource": "deal",
        "operation": "get",
        "dealId": "={{ $json.data.id }}",
        "rawCustomFieldOutput": false
      }
    },
    {
      "id": "c2000000-0000-4000-8000-000000000006",
      "name": "Get organization",
      "type": "n8n-nodes-base.pipedrive",
      "typeVersion": 2,
      "position": [
        200,
        0
      ],
      "parameters": {
        "authentication": "apiToken",
        "resource": "organization",
        "operation": "get",
        "organizationId": "={{ $json.org_id }}"
      }
    },
    {
      "id": "c2000000-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": {
            "Client": "={{ $json.name }}",
            "Project": "={{ $('Get deal').item.json.title }}",
            "Scope": "={{ $('Get deal').item.json.custom_fields.Scope }}",
            "Price": "={{ $('Get deal').item.json.value }} {{ $('Get deal').item.json.currency }}",
            "Valid until": "={{ $now.plus({ days: 30 }).toFormat('d LLLL yyyy') }}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "Client",
              "displayName": "Client",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": false,
              "removed": false
            },
            {
              "id": "Project",
              "displayName": "Project",
              "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": "Price",
              "displayName": "Price",
              "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": "c2000000-0000-4000-8000-000000000008",
      "name": "Pipedrive",
      "type": "n8n-nodes-base.pipedrive",
      "typeVersion": 2,
      "position": [
        640,
        0
      ],
      "parameters": {
        "authentication": "apiToken",
        "resource": "note",
        "operation": "create",
        "content": "=Proposal: {{ $json.file_url }} PDF: {{ $json.deliveries[0].result.pdf_url }}",
        "additionalFields": {
          "deal_id": "={{ $('Loop Over Items').item.json.data.id }}"
        }
      }
    }
  ],
  "connections": {
    "Pipedrive 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 organization",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get organization": {
      "main": [
        [
          {
            "node": "SourceToDocs",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "SourceToDocs": {
      "main": [
        [
          {
            "node": "Pipedrive",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Pipedrive": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  }
}
