My project using the ProfilesAPI works on my computer in development, but does not send a confirmation email on signup.
Double opt-in is on, but the subscription through the API automatically just adds the email to the list without sending or waiting on the confirmation email interaction from the user.
When I push to production, however, the form I have on my website does not create a profile, and then cannot subscribe the profile. Nothing is seen on my Klaviyo portal when a signup is attempted.
Am I doing something wrong?
Code snippet below:
const session = new ApiKeySession(KlaviyoAPIKey);
const profilesApi = new ProfilesApi(session);
export default async function AddEmailSubscriber(email: string) {
let profile: ProfileCreateQuery = {
data: {
type: ProfileEnum.Profile,
attributes: {
email: `${email!}`
}
}
}
let subscribe: SubscriptionCreateJobCreateQuery = {
data: {
type: 'profile-subscription-bulk-create-job',
attributes: {
customSource: 'Homepage Footer Newsletter Subscription Form',
profiles: {
data: '
{
type: 'profile',
attributes: {
email: `${email!}`,
subscriptions: {
email: {marketing: {consent: 'SUBSCRIBED', consentedAt: now}}
},
}
}
]
},
},
relationships: {list: {data: {type: 'list', id: '>redacted]'}}}
}
}
profilesApi.createOrUpdateProfile(profile).then(result => {
console.log(result)
}).catch(error => {
console.log(error)
});
profilesApi.subscribeProfiles(subscribe).then(result => {
console.log(result)
}).catch(error => {
console.log(error)
});
};