Api call not working when deployed, but working locally

I’m working on a website for a business I’m starting.

I setup an API call on the homepage for people to subscribe to a newsletter for when we’re launching our newest product. It’s connected to a Klaviyo account that is gathering the emails. When I run the code locally it works just fine and posts the data, however when I run it on the Netlify servers I still get a ok 200 code, but nothing gets posted to Klaviyo.

Things I have tried to fix the error.

  1. Made sure the Klaviyo information is added to the environment variables on Netlify.
  2. Console logging the data to make sure it is getting passed correctly. However I don’t know how to see that information when its hosted through Netlify, I can only see it is going through correctly on my local branch.
  3. I’ve tried to find similar related posts.

I don’t have any DNS issues, or any Build problems that I can tell. Logs are clean and the website runs fine, and gets a 200 ok response. but the data doesn’t show up in Klaviyo unless sent from localhost.

I’m pretty new with Netlify and API calls in general so there might be something obvious I am missing, any help would be appreciated. Thanks

Hi :wave:t6: @Blake ,

I strongly encourage you to give this docs site a read first as it details how to use our API. This may help clear up your questions. If not, just let us know and we dive deeper.

1 Like

Thanks @SamO I read up on the Netlify API and that pointed me in the right direction. I changed from using NEXT.js pages/api/addnewsletter, to using netlifys .netlify/functions/addnewsletter.