Skip to content

Instantly share code, notes, and snippets.

@shanwixcode
Created January 1, 2021 23:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shanwixcode/11cd95d9d611a6ed33f7785b410d8a31 to your computer and use it in GitHub Desktop.
Save shanwixcode/11cd95d9d611a6ed33f7785b410d8a31 to your computer and use it in GitHub Desktop.
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