Task: WordPress-to-Pipedrive Integration: Automating Contact & Lead Management

n8n workflow:
{"id":"KwfGSgwPQrcD92Gg","meta":{"instanceId":"10a5c562c9a735159d1eb02179d8395916de079abee02b87ec2c2b97f278000a"},"name":"WordPress-to-Pipedrive Integration: Automating Contact & Lead Management","tags":[{"id":"vlXJOdNziJAjaypM","name":"Templates","createdAt":"2023-11-29T10:41:32.132Z","updatedAt":"2023-11-29T10:41:32.132Z"}],"nodes":[{"id":"51bde0f3-2300-4a85-89d3-cf7d7b43c94d","name":"Sticky Note","type":"n8n-nodes-base.stickyNote","position":[-120,0],"parameters":{"width":611,"height":1168.7934508816131,"content":"### Webhook Setup for Contact Form 7 in WordPress\n* Install Contact Form 7: Begin by installing the Contact Form 7 plugin in your WordPress site. This plugin allows for easy creation and management of contact forms. You can download and install it from the WordPress plugin directory here: [Contact Form 7 Plugin](https://example.com/).\n* Use CF7 Webhook Extension: To enable webhook functionality in CF7, utilize the CF7 Webhook extension. This extension allows you to send form data to a specified URL, which is crucial for integrating with your workflow. You can find more information and download it here: [CF7 Webhook Extension](https://example.com/).\n\n### Configuring the Webhook with Contact Form 7 in WordPress\n* Obtain n8n Webhook URL: First, retrieve your n8n webhook URL. This is the specific address where the data from your WordPress contact form will be sent.\n* Update Contact Form 7 with Custom Form Code: In your WordPress dashboard, go to the Contact Form 7 plugin. Create a new form or edit an existing one, and insert the following code to create a custom contact form: \n\n<label> Name [text* your-name autocomplete:name] </label>\n<label> E-Mail-Adresse [email* your-email autocomplete:email] </label> \n<label> Unternehmen [text* company] </label> \n[submit \"Senden\"]    \n\nThis code will generate a form with fields for Name, Email Address, and Company.\n* Insert n8n Webhook URL in the Webhook Field: In the settings of your CF7 form, locate the webhook field. Here, paste the n8n webhook URL that you obtained in step 1. This step is crucial to ensure that the data from your form is sent to your n8n workflow.\n* Save and Test Your Form: After configuring the webhook URL, save your form. It's recommended to test the form to ensure that data is correctly being transmitted to your n8n webhook.\n\n### Retrieving API Key in Pipedrive\n* Login to Pipedrive: Sign in to your Pipedrive account.\n* Access Settings: Navigate to your personal settings. This is usually accessible via your profile icon in the top right corner of the Pipedrive interface.\n* Find API Key: Look for the section labeled “API” or “API Key”. In this section, your personal API key will be displayed. This key is unique to your account and allows applications like n8n to access your Pipedrive data.\n* Copy the API Key: Copy the displayed API key.\n\n### Setting Up Pipedrive Credentials in n8n\n* Add Credentials: Click on the option in the node to add or select new credentials. Choose “Pipedrive API” as the type of credentials.\n* Enter the API Key: Paste the API key you copied from Pipedrive into the appropriate field.\n* Save the Credentials: Save the credentials (name it). Your n8n workflow can now communicate with Pipedrive.\n\n![Source example](https://kapio.eu/kapio_logo.jpeg)\nYou need help: Then write to us at hallo@kapio.eu\nWebsite: www.kapio.eu"},"typeVersion":1},{"id":"ba7c4fdd-5502-408b-ba04-484f3d3b6240","name":"Create Lead","type":"n8n-nodes-base.pipedrive","position":[2020,400],"parameters":{"title":"=Website request: {{ $('Webhook').item.json.body.company }}","resource":"lead","person_id":"={{ $json.person_id }}","associateWith":"person","additionalFields":{"label_ids":["2a875ff0-eb41-11ed-80d0-59a724a2c908"]}},"credentials":{"pipedriveApi":{"id":"20","name":"Pipedrive kapio"}},"typeVersion":1},{"id":"0a211c74-0ea2-4385-a19f-5d35603ca64f","name":"Search Person in Pipedrive","type":"n8n-nodes-base.httpRequest","position":[900,420],"parameters":{"url":"=https://api.pipedrive.com/v1/itemSearch?term={{ $json.body['your-email'] }}&field_key=email&exact_match=true&item_types=person","options":{},"authentication":"predefinedCredentialType","nodeCredentialType":"pipedriveApi"},"credentials":{"pipedriveApi":{"id":"20","name":"Pipedrive kapio"}},"typeVersion":4.1},{"id":"79fd1b5d-874f-4ffd-ab3c-1969fb71e7c2","name":"Check if person is in Pipedrive and output the ID","type":"n8n-nodes-base.code","position":[1120,420],"parameters":{"jsCode":"const inputItems = $input.all();\n\n// Check if there are items and that the items array is not empty\nconst hasItems = inputItems.length > 0 && inputItems[0]?.json?.data?.items.length > 0;\n\n// Retrieve the ID of the first item if available\nconst firstItemId = hasItems ? inputItems[0].json.data.items[0].item.id : null;\n\nreturn { hasItems, firstItemId };\n"},"typeVersion":2,"alwaysOutputData":true},{"id":"9664b373-11f8-4dbb-adcf-5db14498f03d","name":"IF Person exists in Pipedrive","type":"n8n-nodes-base.if","position":[1320,420],"parameters":{"conditions":{"boolean":[{"value1":"={{ $json.hasItems }}","value2":true}]}},"typeVersion":1},{"id":"d98569ea-9879-4e65-b310-82f199abe436","name":"Pipedrive","type":"n8n-nodes-base.pipedrive","position":[1540,520],"parameters":{"name":"={{ $('Webhook').item.json.body[\"your-name\"] }}","resource":"person","additionalFields":{"email":["={{ $('Webhook').item.json.body[\"your-email\"] }}"]}},"credentials":{"pipedriveApi":{"id":"20","name":"Pipedrive kapio"}},"typeVersion":1},{"id":"1afebef2-cb8c-4ef7-bb37-820b9d20f8fd","name":"Webhook","type":"n8n-nodes-base.webhook","position":[720,420],"webhookId":"d296fe58-4ba1-4089-ac91-88cd07a40571","parameters":{"path":"d296fe58-4ba1-4089-ac91-88cd07a40571","options":{},"httpMethod":"POST"},"typeVersion":1},{"id":"67813ff5-2017-4850-b9b9-2267f1bc60e6","name":"New Person ID","type":"n8n-nodes-base.code","position":[1820,400],"parameters":{"jsCode":"// Check whether the value from the previous node is available\nlet personId;\n\n// Check whether the value of 'IF Person exists in Pipedrive' node is present\nif ($('IF Person exists in Pipedrive').item.json.firstItemId) {\n    personId = $('IF Person exists in Pipedrive').item.json.firstItemId;\n} \n// If the above value is not available, check whether a value of '$('Pipedrive').item.json.id' is available\nelse if ($('Pipedrive').item.json.id) {\n    personId = $('Pipedrive').item.json.id;\n}\n\n// If a value was found for personId, it is output as a new variable\nif (personId) {\n    return { person_id: personId };\n} else {\n    return { error: 'Keine Person-ID gefunden' };\n}\n"},"typeVersion":2},{"id":"bd5b9b7d-0450-4739-9956-51aa8339d181","name":"Create Note","type":"n8n-nodes-base.pipedrive","position":[2180,400],"parameters":{"content":"=Website-Request:<br>\nName: {{ $('Webhook').item.json.body[\"your-name\"] }} <br>\nE-Mail: {{ $('Webhook').item.json.body[\"your-email\"] }}<br>\nCompany: {{ $('Webhook').item.json.body.company }}","resource":"note","additionalFields":{"lead_id":"={{ $json.id }}","person_id":"={{ $('New Person ID').item.json.person_id }}"}},"credentials":{"pipedriveApi":{"id":"20","name":"Pipedrive kapio"}},"typeVersion":1},{"id":"b864919c-1438-4705-8822-0752c88f3a76","name":"Create Activity","type":"n8n-nodes-base.pipedrive","position":[2340,400],"parameters":{"type":"task","subject":"Contacting new website lead","resource":"activity","additionalFields":{"person_id":"={{ $('New Person ID').item.json.person_id }}","customProperties":{"property":[{"name":"lead_id","value":"={{ $('Create Lead').item.json.id }}"}]}}},"credentials":{"pipedriveApi":{"id":"20","name":"Pipedrive kapio"}},"typeVersion":1}],"active":true,"pinData":{},"settings":{"executionOrder":"v1"},"versionId":"1392a3ca-f07b-4acf-8ff5-3e692445696d","connections":{"Webhook":{"main":[[{"node":"Search Person in Pipedrive","type":"main","index":0}]]},"Pipedrive":{"main":[[{"node":"New Person ID","type":"main","index":0}]]},"Create Lead":{"main":[[{"node":"Create Note","type":"main","index":0}]]},"Create Note":{"main":[[{"node":"Create Activity","type":"main","index":0}]]},"New Person ID":{"main":[[{"node":"Create Lead","type":"main","index":0}]]},"Search Person in Pipedrive":{"main":[[{"node":"Check if person is in Pipedrive and output the ID","type":"main","index":0}]]},"IF Person exists in Pipedrive":{"main":[[{"node":"New Person ID","type":"main","index":0}],[{"node":"Pipedrive","type":"main","index":0}]]},"Check if person is in Pipedrive and output the ID":{"main":[[{"node":"IF Person exists in Pipedrive","type":"main","index":0}]]}}}