Skip to main content
Contributor I
October 4, 2024
Solved

Profiles and Subscriptions API only works in development?

  • October 4, 2024
  • 2 replies
  • 159 views

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)

   });

 

};

    This topic has been closed for replies.
    Best answer by brittany.klaviyo.dev

    Hi @smallbusinesswoshi! Are you still having issues with this? My recommendation would be to check in on the API logs in your account (https://www.klaviyo.com/developer-tools/logs) and seeing if

    A) your production requests are reaching us, and

    B) what the difference is between your production and development accounts. When we see discrepancies between development and production, it’s common that the production API key doesn’t have all the same permissions as the development key.

    2 replies

    brittany.klaviyo.dev
    Klaviyo Alum
    October 24, 2024

    Hi @smallbusinesswoshi! Are you still having issues with this? My recommendation would be to check in on the API logs in your account (https://www.klaviyo.com/developer-tools/logs) and seeing if

    A) your production requests are reaching us, and

    B) what the difference is between your production and development accounts. When we see discrepancies between development and production, it’s common that the production API key doesn’t have all the same permissions as the development key.

    Contributor I
    November 14, 2024

    Hi Brittany! Thanks for the response. I’m still having issues with this. So I’m using the same credentials for both the development and production environments, but the development environment subscribes users without sending the double opt-in email, nor is it triggering the welcome flow. And the production environment does not seem to send/receive responses at all. I’m not sure what to do at this point.