{
  "name": "Trevilo: enquiry to a Pipedrive person, deal and note",
  "nodes": [
    {
      "parameters": {
        "content": "## Trevilo: enquiry to a Pipedrive person, deal and note\n\n1. Open **Trevilo enquiry**, copy the **Production URL**.\n2. In **Trevilo enquiry**, create a **Header Auth** credential: name `X-Webhook-Key`, value a long random key.\n3. In Trevilo, add a rule about \"A new enquiry or quote\", \"A product\" or \"A service\" and send it to an n8n connection with that URL. Set its login to **API key in a header**, header name `X-Webhook-Key`, and the same key.\n4. In each Pipedrive step, create a **Pipedrive API** credential with your personal API token (Pipedrive: Personal preferences, API).\n5. Publish, then send a test enquiry from Trevilo. A person, a deal and a note appear in Pipedrive.",
        "height": 420,
        "width": 460
      },
      "id": "14a40099-c9f3-5f80-a1e1-8ef5e32224d4",
      "name": "Setup",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -560,
        -280
      ]
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "trevilo-pipedrive",
        "authentication": "headerAuth",
        "options": {}
      },
      "id": "79003e43-d1cc-5bcb-aba6-644ff03ede8b",
      "name": "Trevilo enquiry",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2.2,
      "position": [
        0,
        0
      ],
      "webhookId": "20c60780-79f0-5a02-8ffd-e529f1c568c3"
    },
    {
      "parameters": {
        "operation": "removeItemsSeenInPreviousExecutions",
        "dedupeValue": "={{ $('Trevilo enquiry').item.json.headers['idempotency-key'] }}",
        "options": {}
      },
      "id": "a4490fbf-ee75-546c-8834-65a708fa6a76",
      "name": "Skip repeat deliveries",
      "type": "n8n-nodes-base.removeDuplicates",
      "typeVersion": 2,
      "position": [
        220,
        0
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "a20f2fa4-5bf4-5982-a9b5-f0c954fe6736",
              "leftValue": "={{ [null, 'inquiry', 'product', 'service'].includes($('Trevilo enquiry').item.json.body.enquiry?.intent ?? null) && Boolean($('Trevilo enquiry').item.json.body.contact?.email) }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "c67e7ab6-8d26-537e-92b4-1a2a16ecbe3d",
      "name": "Lead with email?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        440,
        0
      ]
    },
    {
      "parameters": {
        "resource": "person",
        "operation": "search",
        "term": "={{ $('Trevilo enquiry').item.json.body.contact.email }}",
        "exactMatch": true,
        "limit": 1,
        "additionalFields": {
          "fields": [
            "email"
          ]
        }
      },
      "id": "6576903f-4312-5392-8c72-23c35a19e072",
      "name": "Find person by email",
      "type": "n8n-nodes-base.pipedrive",
      "typeVersion": 2,
      "position": [
        660,
        -100
      ],
      "alwaysOutputData": true
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "ceb77689-85e4-53b6-8038-e72d05c7daa3",
              "leftValue": "={{ Boolean($json.id) }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "a8d63269-3cb5-5dad-bf62-04b078111798",
      "name": "Already in Pipedrive?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        880,
        -100
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "531893b3-7509-54d6-9cb9-ceb24cf68402",
              "name": "personId",
              "type": "number",
              "value": "={{ $json.id }}"
            }
          ]
        },
        "options": {}
      },
      "id": "8010e6c7-091a-56b8-b2c6-ca821e1adc50",
      "name": "Use the existing person",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        1100,
        -200
      ]
    },
    {
      "parameters": {
        "resource": "person",
        "operation": "create",
        "name": "={{ $('Trevilo enquiry').item.json.body.enquiry?.name || $('Trevilo enquiry').item.json.body.contact.email }}",
        "additionalFields": {
          "emails": {
            "emailProperties": [
              {
                "value": "={{ $('Trevilo enquiry').item.json.body.contact.email }}",
                "primary": true,
                "label": "work"
              }
            ]
          },
          "phones": {
            "phoneProperties": [
              {
                "value": "={{ $('Trevilo enquiry').item.json.body.contact?.phone || '' }}",
                "primary": true,
                "label": "mobile"
              }
            ]
          }
        },
        "rawCustomFieldKeys": true
      },
      "id": "f94cb702-daef-5ebe-8792-913c30a2281e",
      "name": "Create person",
      "type": "n8n-nodes-base.pipedrive",
      "typeVersion": 2,
      "position": [
        1100,
        0
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "8fa14914-a5e5-55b3-8cd7-558d07c6e962",
              "name": "personId",
              "type": "number",
              "value": "={{ $json.id }}"
            }
          ]
        },
        "options": {}
      },
      "id": "43a3571d-86cb-50f7-9c25-1a86caadd107",
      "name": "Use the new person",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        1320,
        0
      ]
    },
    {
      "parameters": {
        "resource": "deal",
        "operation": "create",
        "title": "=Enquiry: {{ $('Trevilo enquiry').item.json.body.enquiry?.intent_label || 'Not classified' }} from {{ $('Trevilo enquiry').item.json.body.enquiry?.name || $('Trevilo enquiry').item.json.body.contact.email }}",
        "associateWith": "person",
        "person_id": "={{ $json.personId }}",
        "additionalFields": {},
        "rawCustomFieldKeys": true
      },
      "id": "eba698eb-7c66-5a5d-9f88-3ac5774d14b0",
      "name": "Create deal",
      "type": "n8n-nodes-base.pipedrive",
      "typeVersion": 2,
      "position": [
        1540,
        -100
      ]
    },
    {
      "parameters": {
        "resource": "note",
        "operation": "create",
        "content": "={{ $('Trevilo enquiry').item.json.body.enquiry?.message || '' }}\n\nPage: {{ $('Trevilo enquiry').item.json.body.source?.url || '' }}",
        "additionalFields": {
          "deal_id": "={{ $json.id }}"
        }
      },
      "id": "d6f7a9f7-be07-5e96-bce6-dc9983969ebb",
      "name": "Add the message as a note",
      "type": "n8n-nodes-base.pipedrive",
      "typeVersion": 2,
      "position": [
        1760,
        -100
      ]
    }
  ],
  "connections": {
    "Trevilo enquiry": {
      "main": [
        [
          {
            "node": "Skip repeat deliveries",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Skip repeat deliveries": {
      "main": [
        [
          {
            "node": "Lead with email?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Lead with email?": {
      "main": [
        [
          {
            "node": "Find person by email",
            "type": "main",
            "index": 0
          }
        ],
        []
      ]
    },
    "Find person by email": {
      "main": [
        [
          {
            "node": "Already in Pipedrive?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Already in Pipedrive?": {
      "main": [
        [
          {
            "node": "Use the existing person",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Create person",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create person": {
      "main": [
        [
          {
            "node": "Use the new person",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Use the existing person": {
      "main": [
        [
          {
            "node": "Create deal",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Use the new person": {
      "main": [
        [
          {
            "node": "Create deal",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create deal": {
      "main": [
        [
          {
            "node": "Add the message as a note",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {},
  "meta": {
    "templateCredsSetupCompleted": false
  }
}
