Hello,
So, I wrote a lambda function, hooked it up through an API gateway endpoint.
Typeform sends the data over and it’s quite simple to parse and use. Below i a simplified version of my script. When calling Mailchimp, you can map responses to any fields you’d like too.
(handler here is a custom utility class I have to handle lambda errors, no need to worry about it for this.)
const mailchimp = require('@mailchimp/mailchimp_marketing');
mailchimp.setConfig({
apiKey: 'myKey',
server: 'myServer',
});
const audienceId = 'myAudience';
export const main = handler(async (event) => {
const surveyData = JSON.parse(event.body);
const subscribingUser = {
email: surveyData.form_response.hidden.email,
};
try {
const response = await mailchimp.lists.addListMember(audienceId, {
email_address: subscribingUser.email,
status: 'subscribed',
});
console.log(
`Successfully added contact as an audience member. The contact's id is ${response.id}.`
);
} catch (error) {
console.error(error);
}
});
Enjoy!