Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
const axios = require('axios'); //remember to install the axios npm
var url = 'https://{SERVER}.api.mailchimp.com/3.0/lists/{LIST ID}/members';
var api_key = '{API KEY HERE}';
export function createSub(fname, lname, email) {
return axios({
url: url,
method: 'post',
headers: {
'Authorization': 'Basic ' + api_key,
'Content-Type': 'application/json'
},
data: JSON.stringify({
email_address: email,
status: 'subscribed',
merge_fields: {
FNAME: fname,
LNAME: lname
}
})
})
.then( (response) => {
return {status: response.status, response: response.data};
})
.catch( (error) => {
return {status: error.response.status, response: error.response.data};
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment