Alexis Bedoret
Jul 13 · 1 min read
function getLifecycleStages() {
var service = getService();
var today = new Date().getTime();
var from = today - 1000*60*60*24*7; // Amout of milliseconds in a week.
var url = API_URL + "/contacts/search/v1/external/lifecyclestages?fromTimestamp=" + from + "&toTimestamp=" + today;
var response = UrlFetchApp.fetch(url, {headers: {'Authorization': 'Bearer ' + service.getAccessToken()}});
var result = JSON.parse(response.getContentText());
var matrix = Array();
var row = ["Lifecycle Stage", "Count"];
matrix.push(row);

result.forEach(function(lifecycle) {
matrix.push([lifecycle.lifecycleStage,lifecycle.count]);
});

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("Lifecycle Stages");
// Writing the table to the spreadsheet
var range = sheet.getRange(1,1,matrix.length,matrix[0].length);
range.setValues(matrix);
}

    Alexis Bedoret

    Written by

    I am Alex, one of the founders at Make it Group. We build startups in IoT. Check us out here: makeit-group.com

    Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
    Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
    Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade