我想在我的應用程序中將新註冊添加到Mailchimp列表中。它完美地通過捲曲聲明是這樣的:通過節點和Mailchimp API 3.0將成員添加到Mailchimp列表中
curl --request POST --url 'https://us4.api.mailchimp.com/3.0/lists/[listid]/members' --user 'anystring:[api key]-us4' --header 'content-type: application/json' --data '{"email_address":"[email protected]", "status":"subscribed","merge_fields":{"FNAME":"Freddie","LNAME":"Jones"}}' --include
我使用的請求模塊的Node.js這樣的:
var request = require('request');
request({
url: 'https://us4.api.mailchimp.com/3.0/lists/[list-id]/members',
user: 'anystring:[api-key]',
json: {
"email_address":"[email protected]",
"user":"anystring:[api-key]",
"status":"subscribed",
"merge_fields":{
"FNAME":"Freddie",
"LNAME":"Jones"
}
},
method: 'POST',
headers: {
'Content-Type': 'application/json'
}
}, function(error, response, body){
if(error) {
console.log(error);
} else {
console.log(response.statusCode, body);
}
}
);
但我得到這個錯誤:
401 { type: 'http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/',
title: 'API Key Missing',
status: 401,
detail: 'Your request did not include an API key.',
instance: '' }
我如何正確地制定這個要求?
順便說一句,我編寫了代碼示例中的API密鑰和列表ID。在我的實際要求中,那些是真正的要求。 – tonejac