0

I have more than 5000 deals in Pipedrive and I want to pull all the deals using Pipedrive integration to google sheet.

I tried some script and successfully pull some data but the problem is Pipedrive has only 500 max limit in each page.

So would like to ask how will I able to loop the pagination and to get all the deals.

please see the script below.

function GetPdriveSalesToday() {
  var ss = SpreadsheetApp.openById('xxxxxxxxxxxxxxxxxxxx');
  var sheet = ss.getSheetByName("Sheet6");
  var lastrow = sheet.getLastRow();
  sheet.getRange("Sheet6!A2:C3500").clearContent();

      var url = "https://api.pipedrive.com/v1/deals?filter_id=2699&start=1&limit=500&api_token=xxxxxxxxxxxxxxxxxxxx";
      var response = UrlFetchApp.fetch(url);
      var dataSet = JSON.parse(response.getContentText()); 
      var data;

      for (var i = 0; i < dataSet.data.length; i++) {
        data = dataSet.data[i];
        sheet.appendRow([data.id,data.title,data.e2c4a2838c16e53c6f4cf3b54ac5bfe253310a7a]).getRange(lastrow +1,1);

      }

}
pnuts
  • 58,317
  • 11
  • 87
  • 139
AJRs
  • 11
  • 2
  • Simply change the `start` parameter in your URL querystring. A more robust and accurate approach is to use the information the API be gave you: APIs that return paginated data will often include information that can be used to access other pages. Check the headers of the response. – tehhowch Jul 23 '18 at 03:22
  • Use the same logic you would otherwise use for variable string substitution. – tehhowch Jul 23 '18 at 04:07
  • Thanks for your reply. Ok got the response from API so from here I have a start of 0, then what I want now is to get the 501, 1001... starting point. will you mind telling me how will I loop the page to get all the deals – AJRs Jul 23 '18 at 04:11
  • I know this is too much, and to be honest I don't know what I'm doing now. you mind sending the updated script? I tried to do the work on my own but I'm on my limit. – AJRs Jul 23 '18 at 04:37

1 Answers1

0

They gave an official functional example function about retrieving all records using pagination data which given as additional data once you made your request, have a good at this: https://pipedrive.readme.io/docs/using-pagination-to-retrieve-all-deal-titles

Homer
  • 449
  • 4
  • 9