{
  "nodes": [
    {
      "id": "9246c394-0b95-48c7-a011-271dcea72081",
      "name": "When clicking \u2018Execute workflow\u2019",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        416,
        304
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "ba2e7076-7e79-4e54-b46f-5564d9545684",
      "name": "Get many deals",
      "type": "n8n-nodes-base.pipedrive",
      "position": [
        640,
        832
      ],
      "parameters": {
        "filters": {},
        "operation": "getAll",
        "returnAll": true
      },
      "credentials": {
        "pipedriveApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "223b3cbe-9a9c-420a-ab56-04af64eac3f8",
      "name": "Get many notes",
      "type": "n8n-nodes-base.pipedrive",
      "position": [
        1072,
        272
      ],
      "parameters": {
        "resource": "note",
        "operation": "getAll",
        "returnAll": true,
        "additionalFields": {
          "deal_id": "={{ $json.id }}"
        }
      },
      "credentials": {
        "pipedriveApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "934f9442-ab8c-4542-bac6-c232b5580d2c",
      "name": "Code",
      "type": "n8n-nodes-base.code",
      "position": [
        880,
        304
      ],
      "parameters": {
        "jsCode": "// Code node: Rename stage_id numbers to names\n// Input: items with item.json.stage_id\n// Output: item.json.stage_name (string)\n\nconst stageMap = {\n  1: \"Prospecting\",\n  2: \"Qualified\",\n  3: \"Proposal Sent\",\n  4: \"Negotiation\",\n  5: \"Closed Won\"\n};\n\nreturn items.map(item => {\n  const stageId = item.json.stage_id;\n  item.json.stage_name = stageMap[stageId] || `Unknown (${stageId})`;\n  return item;\n});\n"
      },
      "typeVersion": 2
    },
    {
      "id": "84d9ce96-9150-4300-8080-2be123b97a5f",
      "name": "OpenAI Chat Model3",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        1936,
        768
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini",
          "cachedResultName": "gpt-4o-mini"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "2eee8c39-6df0-4a86-a590-21d1f1d05533",
      "name": "Sticky Note8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -80,
        112
      ],
      "parameters": {
        "width": 400,
        "height": 912,
        "content": "\n## \u2699\ufe0f Setup Instructions\n\n### 1\ufe0f\u20e3 Set Up OpenAI Connection\n1. Go to [OpenAI Platform](https://platform.openai.com/api-keys)  \n2. Navigate to [OpenAI Billing](https://platform.openai.com/settings/organization/billing/overview)  \n3. Add funds to your billing account  \n4. Copy your API key into the **OpenAI credentials** in n8n  \n\n### 2\ufe0f\u20e3 Connect Pipedrive\n1. In **Pipedrive** \u2192 **Personal preferences \u2192 API** \u2192 copy your **API token**  \n   - URL shortcut: `https://{your-company}.pipedrive.com/settings/personal/api`  \n2. In **n8n** \u2192 **Credentials \u2192 New \u2192 Pipedrive API**  \n   - **Company domain**: `{your-company}` (the subdomain in your Pipedrive URL)  \n   - **API Token**: paste the token from step 1 \u2192 **Save**  \n3. In the **Pipedrive nodes**, select your Pipedrive credential and (optionally) set filters (e.g., owner, label, created time).\n\n\n\n## \ud83d\udcec Contact\nNeed help extending this (e.g., send summaries by Slack/Email, or auto-create tasks in Pipedrive)?\n\n- \ud83d\udce7 **rbreen@ynteractive.com**  \n- \ud83d\udd17 **[Robert Breen](https://www.linkedin.com/in/robert-breen-29429625/)**  \n- \ud83c\udf10 **[ynteractive.com](https://ynteractive.com)**\n"
      },
      "typeVersion": 1
    },
    {
      "id": "97501f67-851f-4876-b8eb-1b61e4be2906",
      "name": "Sticky Note56",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        352,
        112
      ],
      "parameters": {
        "color": 7,
        "width": 1984,
        "height": 912,
        "content": "# \ud83d\udcca Pipedrive Deals Daily Summary (n8n + OpenAI)\n\nThis workflow fetches **deals and their notes from Pipedrive**, cleans up stage IDs into names, aggregates the information, and uses **OpenAI** to generate a daily summary of your funnel.\n\n---"
      },
      "typeVersion": 1
    },
    {
      "id": "35293ed8-8d18-4a3e-826d-c60c37cab6ab",
      "name": "Sticky Note9",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        544,
        432
      ],
      "parameters": {
        "color": 3,
        "width": 288,
        "height": 544,
        "content": "### 2\ufe0f\u20e3 Connect Pipedrive\n1. In **Pipedrive** \u2192 **Personal preferences \u2192 API** \u2192 copy your **API token**  \n   - URL shortcut: `https://{your-company}.pipedrive.com/settings/personal/api`  \n2. In **n8n** \u2192 **Credentials \u2192 New \u2192 Pipedrive API**  \n   - **Company domain**: `{your-company}` (the subdomain in your Pipedrive URL)  \n   - **API Token**: paste the token from step 1 \u2192 **Save**  \n3. In the **Pipedrive Tool** node, select your Pipedrive credential and (optionally) set filters (e.g., owner, label, created time).\n"
      },
      "typeVersion": 1
    },
    {
      "id": "2ab2ecd5-6e76-45e6-a17c-6bcd103a42d5",
      "name": "Sticky Note11",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1824,
        608
      ],
      "parameters": {
        "color": 3,
        "width": 288,
        "height": 304,
        "content": "### 1\ufe0f\u20e3 Set Up OpenAI Connection\n1. Go to [OpenAI Platform](https://platform.openai.com/api-keys)  \n2. Navigate to [OpenAI Billing](https://platform.openai.com/settings/organization/billing/overview)  \n3. Add funds to your billing account  \n4. Copy your API key into the **OpenAI credentials** in n8n  "
      },
      "typeVersion": 1
    },
    {
      "id": "c1dee969-580e-4e71-93c0-68eaa8ff08eb",
      "name": "Combine Notes",
      "type": "n8n-nodes-base.summarize",
      "position": [
        1168,
        656
      ],
      "parameters": {
        "options": {},
        "fieldsToSplitBy": "deal_id",
        "fieldsToSummarize": {
          "values": [
            {
              "field": "content",
              "separateBy": "=,",
              "aggregation": "concatenate"
            },
            {
              "field": "deal.title",
              "aggregation": "max"
            }
          ]
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "8a8861ec-df79-4c9a-8b15-fab444d4094f",
      "name": "Set Field Names",
      "type": "n8n-nodes-base.set",
      "position": [
        1360,
        496
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "1d2af38f-855d-435a-b70c-24cf560d103f",
              "name": "stage_name",
              "type": "string",
              "value": "={{ $('Code').item.json.stage_name }}"
            },
            {
              "id": "eb58ba6e-4722-4cc5-be7c-031a823a3488",
              "name": "deal.title",
              "type": "string",
              "value": "={{ $json.max_deal_title }}"
            },
            {
              "id": "d4fe6419-7954-450d-87ab-788149086bd5",
              "name": "content",
              "type": "string",
              "value": "={{ $json.concatenated_content }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "1968ceb0-3c68-4ef8-8186-c0a0a2767641",
      "name": "Aggregate for Agent",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        1520,
        384
      ],
      "parameters": {
        "options": {},
        "aggregate": "aggregateAllItemData"
      },
      "typeVersion": 1
    },
    {
      "id": "f777571b-59aa-4d2d-b371-c7c8415d25f8",
      "name": "Turn Objects to Text",
      "type": "n8n-nodes-base.set",
      "position": [
        1728,
        320
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "9578adb8-b0e3-4629-a375-8ac9585022f2",
              "name": "data",
              "type": "string",
              "value": "={{ $json.data }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "8a3952d0-4a24-4903-86b4-dad3d98dbf6d",
      "name": "Summarize Pipedrive",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        1984,
        288
      ],
      "parameters": {
        "text": "=Deals: {{ $json.data }}",
        "options": {
          "systemMessage": "You are a helpful assistant. Do a daily summary of the deals in our pipedrive funnel. "
        },
        "promptType": "define"
      },
      "typeVersion": 2.2
    }
  ],
  "connections": {
    "Code": {
      "main": [
        [
          {
            "node": "Get many notes",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Combine Notes": {
      "main": [
        [
          {
            "node": "Set Field Names",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get many deals": {
      "main": [
        [
          {
            "node": "Code",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get many notes": {
      "main": [
        [
          {
            "node": "Combine Notes",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Field Names": {
      "main": [
        [
          {
            "node": "Aggregate for Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model3": {
      "ai_languageModel": [
        [
          {
            "node": "Summarize Pipedrive",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Aggregate for Agent": {
      "main": [
        [
          {
            "node": "Turn Objects to Text",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Turn Objects to Text": {
      "main": [
        [
          {
            "node": "Summarize Pipedrive",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When clicking \u2018Execute workflow\u2019": {
      "main": [
        [
          {
            "node": "Get many deals",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}