I'm trying to regularly export all subscribers from an audience in Mailchimp into a Google Sheet. For that I wrote some code in Google Apps Script. The script is running without any errors but I also don't get any data. The protocol keeps saying [null].
I double and triple checked all the keys. I hope anyone can point me to the right direction.
Here is my script:
function chimpSubscribers() {
var API_KEY = 'MYKEY'; // MailChimp API Key
var LIST_ID = 'MYLIST'; // MailChimp List ID
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("UpdateList");
var dc = API_KEY.split('-')[1];
var api = 'https://'+ dc +'.api.mailchimp.com/3.0';
var count = 1000; // Max number of subscribers
var memberList = '/lists/'+LIST_ID+'/members/?count='+count
options = {"headers": {"authorization": 'apikey '+API_KEY}};
var apiCall = function(endpoint){
apiResponseMembers = UrlFetchApp.fetch(api+endpoint,options);
json = JSON.parse(apiResponseMembers);
return json
}
var members = apiCall(memberList);
if (members) {
var email_address = members.email_address;
var report = [email_address];
Logger.log(report);
// Clear data in spreadsheet
sheet.clear();
// Insert data into spreedsheet
sheet.appendRow(["E-Mail"]);
sheet.appendRow(report);
}
}
question from:
https://stackoverflow.com/questions/65901996/why-is-my-mailchimp-api-call-in-google-apps-script-not-returning-anything 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…