You are correct, the API key gives access to your account and should therefore be kept private. There isn't a way to use the MailChimp API without providing an API key, but if you are only using it to subscribe users, you can do this through a simple AJAX call instead. This method uses a User ID instead of a private API key to identify your account.
The request below is adapted from this answer:
$.ajax({
type: 'post',
url: 'http://xxxxx.us#.list-manage.com/subscribe/post-json?u=xxxxx&id=xxxx&c=?',
data: $('form').serialize(),
cache : false,
dataType : 'json',
contentType: "application/json; charset=utf-8",
error : function(err) { alert("Could not connect to the registration server. Please try again later."); },
success : function(data) {
if (data.result != "success") {
//Failed
} else {
//Success
}
}
});
To find the values that need to be placed in the url
string, follow the instructions on this page from MailChimp's knowledgebase. You'll need your username, the correct us#
server, the u
value (which is the User ID previously described), and the id
value (which is the list ID).