Hello,
Any idea why this simple script is working fine on Safari but not in Chrome/Firefox?
The HTTP status is always the same 202 though, supposedly success.
Thank for your help!
const options = {
method: "POST",
mode: "cors",
headers: {
revision: "2024-10-15.pre",
"content-type": "application/vnd.api+json"
},
body: JSON.stringify({
data: {
type: "subscription",
attributes: {
profile: {
data: {
type: "profile",
attributes: {
email: "sarah2.mason@klaviyo-demo.com",
subscriptions: {
email: {
marketing: {
consent: "SUBSCRIBED"
}
}
}
}
}
}
},
relationships: {
list: {
data: {
type: "list",
id: "xxx"
}
}
}
}
})
};
fetch("https://a.klaviyo.com/client/subscriptions?company_id=xxx", options)
.then((response) => {
console.log("HTTP Status:", response.status, response.statusText);
if (!response.ok) {
throw new Error(
`Request failed: ${response.status} - ${response.statusText}`
);
}
return response.text();
})
.then((text) => {
console.log("Raw Response Text:", text);
if (text) {
const json = JSON.parse(text);
console.log("Parsed Response JSON:", json);
} else {
console.log("No response body received.");
}
})
.catch((error) => {
console.error("Fetch error:", error.message);
});