Hello everyone!
I am encountering a weird issue trying to subscribe an email through the API. I have a custom form created on a NextJS application, and whenever a user adds their email, i post the email to https://a.klaviyo.com/api/profile-subscription-bulk-create-jobs/ with all the required options (code further down.) I get back a 202 response with the status “Accepted”, but, the email cannot be found in a list, or anywhere for that matter.
The list has the “Double opt in” disabled.
Im saying its weird because a week ago everything worked without any issue and no change to the code happened since. And also the response seems ok.
Here is the code i am using:
async function subscribe(request, response) {
const { email, listId } = JSON.parse(request.body);
const options = {
method: "POST",
headers: {
accept: "application/json",
revision: "2023-02-22",
"content-type": "application/json",
Authorization: `Klaviyo-API-Key ${APIKey}`,
},
body: JSON.stringify({
data: {
type: "profile-subscription-bulk-create-job",
attributes: {
list_id: listId,
custom_source: "Marketing Website",
subscriptions: [
{
channels: { email: ["MARKETING"] },
email,
},
],
},
},
}),
};
try {
const res = await fetch(
"https://a.klaviyo.com/api/profile-subscription-bulk-create-jobs/",
options
);
response.json({
response: res,
});
} catch (error) {
response.json({
error
});
}
}
Ive triple checked the list id exists and is sent correctly, triple checked the API key is correct.
Ive tried creating a brand new list and still doesn't work.
Ive ran out of options so any ideas would be helpful.
Thank you!