Skip to content

Instantly share code, notes, and snippets.

@markpinero
Created April 13, 2020 21:40
Show Gist options
  • Select an option

  • Save markpinero/b5c2c2ea16468869209917f80240c2a5 to your computer and use it in GitHub Desktop.

Select an option

Save markpinero/b5c2c2ea16468869209917f80240c2a5 to your computer and use it in GitHub Desktop.
import querystring from 'querystring';
import fetch from 'node-fetch';
const API_KEY = '';
const LIST_ID = '';
const URL = `https://emailoctopus.com/api/1.5/lists/${LIST_ID}/contacts`;
exports.handler = async (event, context) => {
const params = querystring.parse(event.body);
if (event.httpMethod !== 'POST) {
return { statusCode: 405, body: 'Method Not Allowed' }
}
return fetch(URL, {
headers: { "Accept": "application/json" },
method: 'POST',
body: JSON.stringify({
api_key: API_KEY,
email_address: params.email,
fields: {
FirstName: params.firstName,
LastName: params.lastName,
},
status: 'SUBSCRIBED'
})
})
.then((response) => response.json())
.then((data) => ({
statusCode: 201,
body: data,
}))
.catch((err) => ({ statusCode: 422, body: String(err) }))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment