I need to pass subscribers to mailchimp. My best idea so far, as the project already uses jQuery, is to use $.post()
, but I am not able to convert the function inside the docs into my working version. I got three questions:
- How can I authenticate myself using my API key?
- How can I send the
userData
? - How can I display a success or failure message?
Mailchimp recommends me to:
To add someone to your list, send a POST request to the List Members endpoint: /3.0/lists/9e67587f52/members/. The request body should be a JSON object that has the member information you want to add, with status and any other required list fields.
I have stored all necessary data inside my code:
var API_BASE = 'https://us6.api.mailchimp.com/3.0';
var LIST_ID = '********';
//combine to post link
var POST_URL = API_BASE + '/lists/' + LIST_ID + '/members/'
// API_KEY for authentication
var API_KEY = '*******************-us6'
// userData to send to mailchimp
var userData = {
"email_address": self.mailAddress,
"status": "subscribed",
"merge_fields": {
"BANKNAME": self.bankName,
"PHONESYS": self.phoneSystem
}
}
The data already follows mailchimps guidelines for posting JSON objects. How can I use these data combined with jQuery.post( url \[, data \] \[, success \] \[, dataType \] )
?
Although I have seen in the docs, that there are .done()
and .fail
messages. Can I use these to give the user a response like "success" or "error"?