Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update: newsletter api endpoint and payload #400

Merged
merged 14 commits into from
Feb 28, 2024
34 changes: 21 additions & 13 deletions blocks/newsletter-signup/newsletter-signup.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,33 @@

async function submitForm(block, fd) {
const formData = new FormData(block.querySelector('form'));
const payload = {
const formInfo = {
email: formData.get('email'),
dataFields: {
catnewsletter: formData.get('cats') === 'on',
dognewsletter: formData.get('dogs') === 'on',
},
mergeNestedObjects: true,
createNewFields: true,
first_name: formData.get('name'),
catnewsletter: formData.get('cats') === 'on',
dognewsletter: formData.get('dogs') === 'on',
country: 'en-US', // rework later
};

const apiKey = 'APIEvent-74e121c6-6308-c35e-8320-d335ee59f191';

const payload = {
ContactKey: formInfo.email,
EventDefinitionKey: apiKey,
Data: formInfo,
};

const fetchOpts = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Api-Key': '3e7a9624572b4827b156af44e72fceaa',
},
body: JSON.stringify(payload),
'Content-Type': 'application/json',
};

try {
const res = await fetch('https://api.iterable.com/api/users/update', fetchOpts);
const baseUri =

Check failure on line 42 in blocks/newsletter-signup/newsletter-signup.js

View workflow job for this annotation

GitHub Actions / build

There should be no line break before or after '='
'https://aem-eds-petplace.edgecompute.app/services/newsletter';
const res = await fetch(baseUri, fetchOpts);

if (!res.ok) {
let text = 'no detail.';
try {
Expand All @@ -49,7 +57,7 @@
showMessage(block, fd.Success);
pushToDataLayer({
event: 'sign_up',
signup_category: 'newsletter', // Example: 'newsletter'
signup_category: 'newsletter',
});
}
} catch (e) {
Expand Down
Loading