Export Marketo Static List Data to Google Sheet
Hi,
I am trying to pull Marketo static list data to Google Sheets with the help of Google App Script. However, I have observed only 300 records are getting pulled from Marketo. Can someone help me to find a solution for this issue? Sharing the code for the reference.
function updateData() {
const ACCESS_TOKEN = "";
const API_URL = "";
const LIST_ID = "1873"; // Replace with your actual List ID
const PAGE_SIZE = 200; // Number of records per page
let currentPage = 1;
let allLeads = [];
let leads = []; // Initialize leads as an empty array
do {
const DATA_ENDPOINT = `/rest/v1/list/${LIST_ID}/leads.json?maxReturn=${PAGE_SIZE}&page=${currentPage}`;
const response = UrlFetchApp.fetch(API_URL + DATA_ENDPOINT, {
headers: {
"Authorization": "Bearer " + ACCESS_TOKEN
}
});
const content = JSON.parse(response.getContentText());
leads = content.result || []; // Use an empty array if content.result is undefined
allLeads = allLeads.concat(leads);
currentPage++;
} while (leads.length === PAGE_SIZE);
const HEADERS = ['Lead ID', 'First Name', 'Last Name', 'Email'];
const spreadsheet = SpreadsheetApp.getActive();
const sheet = spreadsheet.getSheetByName('Sheet1');
sheet.clear();
sheet.appendRow(HEADERS);
allLeads.forEach(lead => {
const leadId = lead.id;
const firstName = lead.firstName;
const lastName = lead.lastName;
const email = lead.email;
sheet.appendRow([leadId, firstName, lastName, email]);
});
}
**The Access token and API URL has been removed but the code is working fine with them for 300 records pull.