Skip to content

Commit dd381cf

Browse files
committed
Newsletter function
1 parent 68b2bdf commit dd381cf

File tree

4 files changed

+514
-0
lines changed

4 files changed

+514
-0
lines changed

functions/newsletter/newsletter.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
exports.handler = async (event, context) => {
2+
try {
3+
if (event.httpMethod !== "POST") {
4+
// Block GET requests
5+
return { statusCode: 400, body: null };
6+
}
7+
8+
const Hubspot = require("hubspot");
9+
const hubspot = new Hubspot({ apiKey: process.env.HUBSPOT_KEY });
10+
const body = JSON.parse(event.body);
11+
const contact = await hubspot.contacts.createOrUpdate(body.form.email);
12+
13+
return { statusCode: 200, body: JSON.stringify({ success: true }) };
14+
} catch (err) {
15+
return { statusCode: 500, body: err.toString() };
16+
}
17+
};

0 commit comments

Comments
 (0)