Script to import from Pipedrive to google sheets for last 20 days -
i have script importing pipedrive google sheets works great. pull matches last 20 days instead of specific date. clear rows each time , ass them in fresh rather add them next empty row.
function getpipedrivedeals() { var ss = spreadsheetapp.openbyid('sheet name'); var sheet = ss.getsheetbyname("sheet1"); var url = "https://api.pipedrive.com/v1/activities?user_id=0&start=0&limit=500&start_date=2017-06-01&api_token=xxxxxxxxxxxxxxxxxxxx"; var response = urlfetchapp.fetch(url); var dataset = json.parse(response.getcontenttext()); var data; (var = 0; < dataset.data.length; i++) { data = dataset.data[i]; sheet.appendrow([data.user_id, data.type, data.add_time, data.note, data.org_name]); } }
any appreciated, thank in advance.
you can use start_date & end_date parameter fetch last 20 days records , sheet.clear() clear contents of sheet. refer below code. hope helps!
function getpipedrivedeals() { var ss = spreadsheetapp.openbyid('sheet name'); var sheet = ss.getsheetbyname("sheet1"); sheet.clear(); //clear contents of sheet var startdate = getstartdate(); var enddate = utilities.formatdate(new date(), "gmt", "yyyy-mm-dd"); var url = "https://api.pipedrive.com/v1/activities?user_id=0&start=0&start_date="+startdate+"&end_date="+enddate+"api_token=xxxxxxxxxxxxxxxxxxxx"; var response = urlfetchapp.fetch(url); var dataset = json.parse(response.getcontenttext()); var data; (var = 0; < dataset.data.length; i++) { data = dataset.data[i]; sheet.appendrow([data.user_id, data.type, data.add_time, data.note, data.org_name]); } } function getstartdate() { var result = new date(); result.setdate(result.getdate() - 20); return result.convertdate(); } date.prototype.convertdate = function() { var mm = this.getmonth() + 1; var dd = this.getdate(); return [this.getfullyear(), (mm>9 ? '' : '0') + mm, (dd>9 ? '' : '0') + dd ].join('-'); };
Comments
Post a Comment