Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
262 views
in Technique[技术] by (71.8m points)

javascript - Why is my Mailchimp API call in Google Apps Script not returning anything?

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...