upstream #1

Merged
jblu merged 1007 commits from upstream into main 2024-11-04 22:35:57 -06:00
Showing only changes of commit 795d596012 - Show all commits

View File

@ -1,13 +1,15 @@
export default async (req, res) => { export default async (req, res) => {
const { email } = req.body const { email } = req.body
if (!email) { if (!email) {
return res.status(400).json({error: 'Email is required'}) return res.status(400).json({ error: 'Email is required' })
} }
try { try {
const API_KEY = process.env.KLAVIYO_API_KEY const API_KEY = process.env.KLAVIYO_API_KEY
const LIST_ID = process.env.KLAVIYO_LIST_ID const LIST_ID = process.env.KLAVIYO_LIST_ID
const response = await fetch(`https://a.klaviyo.com/api/v2/list/${LIST_ID}/subscribe?api_key=${API_KEY}`, { const response = await fetch(
`https://a.klaviyo.com/api/v2/list/${LIST_ID}/subscribe?api_key=${API_KEY}`,
{
method: 'POST', method: 'POST',
headers: { headers: {
Accept: 'application/json', Accept: 'application/json',
@ -16,11 +18,10 @@ export default async (req, res) => {
// You can add additional params here i.e. SMS, etc. // You can add additional params here i.e. SMS, etc.
// https://developers.klaviyo.com/en/reference/subscribe // https://developers.klaviyo.com/en/reference/subscribe
body: JSON.stringify({ body: JSON.stringify({
profiles: [ profiles: [{ email: email }],
{email: email},
]
}), }),
}) }
)
if (response.status >= 400) { if (response.status >= 400) {
return res.status(400).json({ return res.status(400).json({
error: `There was an error subscribing to the list.`, error: `There was an error subscribing to the list.`,