Created
January 1, 2021 23:24
-
-
Save shanwixcode/11cd95d9d611a6ed33f7785b410d8a31 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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