|
import BLOG from '@/blog.config' |
|
|
|
|
|
|
|
|
|
|
|
|
|
export default function subscribeToMailchimpApi({ email, first_name = '', last_name = '' }) { |
|
const listId = BLOG.MAILCHIMP_LIST_ID |
|
const apiKey = BLOG.MAILCHIMP_API_KEY |
|
if (!email || !listId || !apiKey) { |
|
return {} |
|
} |
|
const data = { |
|
email_address: email, |
|
status: 'subscribed', |
|
merge_fields: { |
|
FNAME: first_name, |
|
LNAME: last_name |
|
} |
|
} |
|
return fetch(`https://us18.api.mailchimp.com/3.0/lists/${listId}/members`, { |
|
method: 'POST', |
|
headers: { |
|
Authorization: `apikey ${apiKey}`, |
|
'Content-Type': 'application/json' |
|
}, |
|
body: JSON.stringify(data) |
|
}) |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export async function subscribeToNewsletter(email, firstName, lastName) { |
|
const response = await fetch('/api/subscribe', { |
|
method: 'POST', |
|
headers: { |
|
'Content-Type': 'application/json' |
|
}, |
|
body: JSON.stringify({ email, first_name: firstName, last_name: lastName }) |
|
}) |
|
const data = await response.json() |
|
return data |
|
} |
|
|