Pipedrive : how to get daily activities from a User

Hey guys

I am trying to build a dashboard for pipedrive = get all activities done yesterday by a user
→ So i try to list all activities mark as done between the day before and today.

The following flow is working except that “start date” are not taken into account… : i have a list of all activities since many weeks before the “end date”

Has anyone had this problem ?

{
  "nodes": [
    {
      "parameters": {
        "value": "={{$json[\"dateVeille\"]}}",
        "dataPropertyName": "dateVeille",
        "custom": true,
        "toFormat": "YYYY-DD-MM",
        "options": {}
      },
      "name": "format_date_day_before",
      "type": "n8n-nodes-base.dateTime",
      "typeVersion": 1,
      "position": [
        -580,
        330
      ]
    },
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        -1050,
        280
      ]
    },
    {
      "parameters": {
        "resource": "activity",
        "operation": "getAll",
        "returnAll": true,
        "additionalFields": {
          "done": true,
          "end_date": "={{new Date()}}",
          "start_date": "={{$json[\"dateVeille\"]}}",
          "user_id": 122
        }
      },
      "name": "Pipedrive",
      "type": "n8n-nodes-base.pipedrive",
      "typeVersion": 1,
      "position": [
        -340,
        170
      ],
      "credentials": {
        "pipedriveApi": "PipedriveApi"
      }
    },
    {
      "parameters": {
        "authentication": "oAuth2",
        "operation": "append",
        "sheetId": "sheetid",
        "range": "test!A:BJ",
        "options": {
          "valueInputMode": "RAW"
        }
      },
      "name": "Google Sheets n8n",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 1,
      "position": [
        -140,
        170
      ],
      "credentials": {
        "googleSheetsOAuth2Api": "GoogleOAuth"
      }
    },
    {
      "parameters": {
        "value": "={{new Date()}}",
        "custom": true,
        "toFormat": "YYYY-DD-MM",
        "options": {}
      },
      "name": "today",
      "type": "n8n-nodes-base.dateTime",
      "typeVersion": 1,
      "position": [
        -710,
        100
      ]
    },
    {
      "parameters": {
        "action": "calculate",
        "value": "={{new Date()}}",
        "operation": "subtract",
        "duration": 1,
        "dataPropertyName": "date",
        "options": {}
      },
      "name": "day_before",
      "type": "n8n-nodes-base.dateTime",
      "typeVersion": 1,
      "position": [
        -770,
        330
      ]
    },
    {
      "parameters": {
        "value": "={{$json[\"dateVeille\"]}}",
        "dataPropertyName": "dateVeille",
        "custom": true,
        "toFormat": "YYYY-DD-MM",
        "options": {}
      },
      "name": "format_date_day_before",
      "type": "n8n-nodes-base.dateTime",
      "typeVersion": 1,
      "position": [
        -580,
        330
      ]
    }
  ],
  "connections": {
    "format_date_day_before": {
      "main": [
        [
          {
            "node": "Pipedrive",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Start": {
      "main": [
        [
          {
            "node": "today",
            "type": "main",
            "index": 0
          },
          {
            "node": "day_before",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Pipedrive": {
      "main": [
        [
          {
            "node": "Google Sheets n8n",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "today": {
      "main": [
        [
          {
            "node": "Pipedrive",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "day_before": {
      "main": [
        [
          {
            "node": "format_date_day_before",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

A couple of things. You connected both dates to the Pipedrive node, but the Pipedrive node it’s not going to wait for both dates and then execute. It will run two times, one with the start date and the end date. Hence, the node executes with a missing date each time. The second issue, you are passing the dates to Pipedrive with the format YYYY-MM-DD, but the API expects ISO 8601.

The example below should solve the issue. To test it, copy it and paste it into a new workflow.


{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "resource": "activity",
        "operation": "getAll",
        "returnAll": true,
        "additionalFields": {
          "done": true,
          "end_date": "={{new Date($json[\"data\"])}}",
          "start_date": "={{new Date($json[\"dateVeille\"])}}",
          "user_id": 11636945
        }
      },
      "name": "Pipedrive",
      "type": "n8n-nodes-base.pipedrive",
      "typeVersion": 1,
      "position": [
        1000,
        300
      ],
      "credentials": {
        "pipedriveApi": {
          "id": "88",
          "name": "asasasas"
        }
      }
    },
    {
      "parameters": {
        "authentication": "oAuth2",
        "operation": "append",
        "sheetId": "sheetid",
        "range": "test!A:BJ",
        "options": {
          "valueInputMode": "RAW"
        }
      },
      "name": "Google Sheets n8n",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 1,
      "position": [
        1240,
        300
      ],
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": null,
          "name": "GoogleOAuth"
        }
      }
    },
    {
      "parameters": {
        "value": "={{new Date()}}",
        "custom": true,
        "toFormat": "YYYY-MM-DD",
        "options": {}
      },
      "name": "today",
      "type": "n8n-nodes-base.dateTime",
      "typeVersion": 1,
      "position": [
        510,
        240
      ]
    },
    {
      "parameters": {
        "action": "calculate",
        "value": "={{new Date()}}",
        "operation": "subtract",
        "duration": 1,
        "dataPropertyName": "dateVeille",
        "options": {}
      },
      "name": "day_before",
      "type": "n8n-nodes-base.dateTime",
      "typeVersion": 1,
      "position": [
        450,
        470
      ]
    },
    {
      "parameters": {
        "value": "={{$json[\"dateVeille\"]}}",
        "dataPropertyName": "dateVeille",
        "custom": true,
        "toFormat": "YYYY-MM-DD",
        "options": {}
      },
      "name": "format_date_day_before1",
      "type": "n8n-nodes-base.dateTime",
      "typeVersion": 1,
      "position": [
        640,
        470
      ]
    },
    {
      "parameters": {
        "mode": "mergeByIndex"
      },
      "name": "Merge",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 1,
      "position": [
        820,
        300
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "today",
            "type": "main",
            "index": 0
          },
          {
            "node": "day_before",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Pipedrive": {
      "main": [
        [
          {
            "node": "Google Sheets n8n",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "today": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "day_before": {
      "main": [
        [
          {
            "node": "format_date_day_before1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "format_date_day_before1": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Merge": {
      "main": [
        [
          {
            "node": "Pipedrive",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

So many thanks @RicardoE105 !
I am going to try that :wink:

So it works perfectly @RicardoE105 !!Great !

My aim now is to know how many tasks are done by this user (“type” field in pipedrive data) : call, email, task…

i was thinking using a “switch” node or maybe “set” node to detect wich type it is but i do not know how to count them …

You can do that with a function node. The example below should do it.

const results = {};

for (const item of items) {
  if (item.json.done === true) {
    if (results[item.json.type] === undefined) {
      results[item.json.type] = 0;
    } else {
      results[item.json.type] = results[item.json.type] + 1
    }
  }
}

return [
  {
    json: {
      ...results
    }
  }
]

This is fantastic!
So many thanks

I was planning to publish this workflow on the WorkFlow Community page to help other people, is this ok for you @RicardoE105 ? (i will mention your great help ! of course)

Glad that it worked. You can share the workflow and not need to mention me at all. Let us know if you have further questions.