Created
April 13, 2020 21:40
-
-
Save markpinero/b5c2c2ea16468869209917f80240c2a5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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