qcobjects-lib-mailchimp-api

QCObjects Lib to subscribe users to a Mailchimp list using official API.

Usage no npm install needed!

<script type="module">
  import qcobjectsLibMailchimpApi from 'https://cdn.skypack.dev/qcobjects-lib-mailchimp-api';
</script>

README

QCObjects Lib Mailchimp API

QCObjects Lib to subscribe users to a Mailchimp list using official API.

Instructions

  1. Install this dependency in your project using npm
npm i --save qcobjects-lib-mailchimp-api
  1. In your config.json file, create the following settings
{
  "mailchimp_api": [
    "$MAILCHIMP_API(MAILCHIMP_API_KEY,MAILCHIMP_API_SERVER,MAILCHIMP_API_LIST)"
  ],
}

Above settings will bring the API Key values from the following environment variables:

MAILCHIMP_API_KEY
MAILCHIMP_API_SERVER
MAILCHIMP_API_LIST
  1. In the code of your microservice, you can import the module using the Import function
  Import ("qcobjects-lib-mailchimp-api");
  1. Usage instructions:

Inside the microservice function you can use the following code:

let microservice = this; // this is the microservice instance

  Promise.all (
    CONFIG.get("mailchimp_api").map(
      api => mailchimpApi.subscribe(
        mailchimpApi.parseApi(api).apiKey,
        mailchimpApi.parseApi(api).server,
        mailchimpApi.parseApi(api).listId,
        formData
      ))
  ).then (() => {
    microservice.done();
  }).catch(e => {
    logger.debug(e.toString());
  });

Learn more about MailChimp official API in the MailChimp Documentation website

This lib is based on the official MailChimp API (https://github.com/mailchimp/mailchimp-marketing-node)

  1. Test the integration
npm test
  1. Start the QCObjects HTTP2 Server
qcobjects-server

If you haven't installed QCObjects before, learn more about Installing QCObjects here