Netlify Functions / Marketing Automation Subscriber Lists

I want to know how I can use a Netlify function to add a subscriber (Name and Email) to my marketing automation software (Aweber, Activecampaign, Infusionsoft etc) and I can find nothing online that will show me how to do this. I have found a number of links that show you how to send an email but not add a name and email to a list. I am not a back end guy (barely know what I am doing on the front end) which is why I am looking at Netlify and the Netlify CMS. I am stuck in Wordpress Hell and looking for a way out but cannot move on without being able to add contacts to numerous marketing automation platforms via cloud functions etc. I clearly want to avoid using a signup form provided by the marketing automation platform and go wit creating my own form. Likewise - I do not want to be limited using a tool like Zapier (I don’t want to pay for Zapier).

For the life of me I cannot figure out why this information isn’t easy to find. I would think this is something large numbers of people would want to do and that someone/ somewhere would have something on this already.

hi there, welcome.

this is specific to mailchimp, but might show some approaches that could be a useful starting point:

Hi chokeul8r,

Did you ever figure this out? I’m in the same boat.

Thanks much,

John

You can use Netlify Forms and connect via api through Zapier, Integromat, Intergrately or Pabbly Connect…to just about any email marketing software (as well as many other applications). Hope that helps :wink:

Also…most email marketing applications have their own embedded forms. You should be able to drop one in and overwrite the css to match your styles (a little work but can be done).

1 Like

Creating a cloud function to do something like this may prove to be fairly complex (particularly if you are using a app that requires O’Auth as opposed to api keys etc).

Part of the issues is storing and updating auth tokens…which would require a database etc.

The fastest and easiest approach would be to use the method provided in my first reply. Use a third party to connect your two apps.

Thank you for sharing that @chokeul8r!

@JohnnyK, if the above doesn’t work for you, or if you need to connect using Netlify Functions itself, do let us know and we can try to work out a solution for you and others who might have this question.

Thank you @chokeul8r for your complete responses.

We are fairly committed to ActiveCampaign at this point.

And I would like to avoid paying for a third party integrator such as Zapier.

Their API uses an account secret for authorization and I’m able to obtain conduct GET requests but am having trouble adding new clients through a POST.

Their example uses php, and I’m just using axios to GET/POST.

@hrishikesh I would eat a bug and do a happy dance if your team could show me an example of how to add a contact to a list. It would probably take you 5 minutes. :laughing:

My post call:

const response = await axios.post(url, {
      email: "myemail@email.com",
      firstName: "John",
    })

And the response from ActiveCampaign:

{
  result_code: 0,
  result_message: 'Could not add contact; missing email address',
  result_output: 'json'
}

It is really holding me up and it would make my week if you could point me in the right direction.

v/r,

John

Looking at the linked documentation, the call should look more like

const response = await axios.post(url, {
  api_action: "contact_sync",
  api_key: "<API-KEY-HERE>",
  email: "myemail@email.com",
  first_name: "John",
  // ... rest of fields
})

The above documentation is v1. ActiveCampaign have a RESTful version 3 API which uses different information in the POST body, including firstName instead of first_name.

This is only a best guess based on reading—I don’t have and AC account to test with.

@coelmay Thank you for responding. I did notice and fixed the key: first_name. And attempted your suggestion. Same response.

I’m really scratching my head on this one.

You might like to try the official ActiveCampaign Node.js API wrapper though it is 4 years old now.

I suggest your best bet is to make enquiries over at the ActiveCampaign Community.

Thank you @coelmay. I posted in StackOverflow and will do the same in ActiveCampaign community.

I tried that node wrapper, and indeed it hasn’t aged well. Thanks for pointing it out tho!

Looking at the documentations, yes the above examples seem to be correct, but if it’s still not working, we’d need an account to test. They don’t seem to have a free plan sadly.

I wanted to make sure to close this and share my answer.

Thanks so much to @reza jafari for his comment in this post on StackOverflow where he brought to my attention the code window on the right margin of Postman where you can choose the language/server from a dropdown and it provides the correctly formatted response.

I was able to get my post working in Postman, and this little trick squared me away. I’ll go ahead and post my solution to close this post.

const axios = require("axios")
const qs = require("qs")

exports.handler = async function (event) {
  const { email, first_name } = JSON.parse(event.body)

  const data = qs.stringify({
    email: email,
    first_name: first_name,
    tags: '"api"',
    "p[1]": "1",
  })
  const config = {
    method: "post",
    url: "https://ACCOUNT.api-us1.com/admin/api.php?api_key=xxxxxxxxx&api_action=contact_sync&api_output=json",
    headers: {
      "Api-Token":
        "xxxxxxxxx",
      "Content-Type": "application/x-www-form-urlencoded",
    },
    data: data,
  }

  try {
    const response = await axios(config)
    return {
      statusCode: 200,
      body: JSON.stringify(response.data),
    }
  } catch (err) {
    return {
      statusCode: 500,
      body: JSON.stringify(err),
    }
  }
}

I have been using mailchimp for a long time now and have never had any problems. I think using the standard Netlify form requires more customization.

Hi @mosss45,

Could you please add more details to that?