upstream #1
@ -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.`,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user