@input-output-hk/mailchimp-subscribe
v0.3.0
Published
Lightweight mailchimp subscriber library supporting custom fields
Downloads
11
Readme
Contents
Features
- Custom fields
Install
npm install --save @input-output-hk/mailchimp-subscribe
or
yarn add @input-output-hk/mailchimp-subscribe
Finding Mailchimp values
Finding the 'uID' value
Finding the 'audienceID' value
Finding the 'listName' value
Examples
Basic without localization
import subscribe from '@input-output-hk/mailchimp-subscribe'
async function submitForm (email) {
try {
const result = await subscribe({
email,
uID: 'XXXXXXXXX',
audienceID: 'XXXXXXXXX',
listName: 'XXXXXX.XXXX'
})
// Instance of MailChimpSuccess
// result.message is the msg value received from Mailchimp
return result
} catch (error) {
// handle error
// error is instance of MailChimpError when error originates from mailchimp
// error.message is the message returned from Mailchimp if the error originated on mailchimp
return error
}
}
Custom fields
import subscribe from '@input-output-hk/mailchimp-subscribe'
async function submitForm (email) {
try {
await subscribe({
email,
uID: 'XXXXXXXXX',
audienceID: 'XXXXXXXXX',
listName: 'XXXXXX.XXXX',
customFields: {
MY_FIELD: 'value',
MY_SECOND_FIELD: 'value_2'
}
})
// Instance of MailChimpSuccess
// result.message is the msg value received from Mailchimp
return result
} catch (error) {
// handle error
// error is instance of MailChimpError when error originates from mailchimp
// error.message is the message returned from Mailchimp if the error originated on mailchimp
return error
}
}
Specifiying a timeout
import subscribe from '@input-output-hk/mailchimp-subscribe'
async function submitForm (email) {
try {
await subscribe({
email,
uID: 'XXXXXXXXX',
audienceID: 'XXXXXXXXX',
listName: 'XXXXXX.XXXX',
// 6000ms
timeout: 6000
})
// Instance of MailChimpSuccess
// result.message is the msg value received from Mailchimp
return result
} catch (error) {
// handle error
// error is instance of MailChimpError when error originates from mailchimp
// error.message is the message returned from Mailchimp if the error originated on mailchimp
return error
}
}
Contributing
Contributions are welcome, see contributing for more info.