@input-output-hk/mailchimp-subscribe

    0.3.0 • Public • Published

    Mailchimp subscribe library

    A lightweight [Mailchimp](https://mailchimp.com/) subscriber library supporting custom fields. Subscribe emails to your mailing lists.

    Mailchimp Subscribe issues Fork Mailchimp Subscribe Mailchimp Subscribe stars Mailchimp Subscribe license CircleCI build Test coverage


    Contents

    1. Features
    2. Install
    3. Finding mailchimp values
    4. Examples
    5. Contributing

    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

    Mailchimp audience sign up forms instructions

    Mailchimp audience embedded forms instructions

    Mailchimp audience embedded forms uid instructions

    Finding the 'audienceID' value

    Mailchimp audience sign up forms instructions

    Mailchimp audience name and defaults

    Mailchimp audience id instructions

    Finding the 'listName' value

    Mailchimp audience sign up forms instructions

    Mailchimp audience embedded forms instructions

    Mailchimp audience embedded forms uid instructions

    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.

    Install

    npm i @input-output-hk/mailchimp-subscribe

    DownloadsWeekly Downloads

    151

    Version

    0.3.0

    License

    MIT

    Unpacked Size

    43.1 kB

    Total Files

    11

    Last publish

    Collaborators

    • martinhunt
    • scottdarby
    • robertmiohk
    • iohkwebdev