Skip to main content
Solved

Shopify: Back in Stock via API not working

  • January 14, 2023
  • 3 replies
  • 418 views

Forum|alt.badge.img+2

Hey, I tried literally everything to add an subscribe to Back in Stock event via the Klaviyo API (Shopify) as described here but it’s not working. I also searched the forums and tried all the provided solutions, but none of them worked.

What I tried

  1. We have a Shopify live store and a development store. They are not connected in any way. I created a second Klaviyo “Dev” account so that we can play around on the Dev store
  2. I added the javascript code to my website. I tried different codes. Self-written, from the docs and code which I found here on the forum

First Code Attempt

fetch("https://a.klaviyo.com/onsite/components/back-in-stock/subscribe", {
    "headers": {
        "accept": "application/json, text/plain, */*",
        "content-type": "application/x-www-form-urlencoded;charset=UTF-8",
    },
    "body": new URLSearchParams({
        "a": "my_public_api_key",
        "email": "myemail@gmail.com",
        "platform": "shopify",
        "variant": 43686047940889,
        "product": 7978217177369,
    }),
    "method": "POST",
    })
    .then(response => {
        console.log(response);
    })
    .catch(err => {
        console.error(err);
    });

Second Code Attempt

$.ajax({
    type: "POST",
    url: "https://a.klaviyo.com/onsite/components/back-in-stock/subscribe",
    data: {
        a: "ACCOUNT_ID", // Klaviyo account public token
        email: "EMAIL", // Email address entered in form
        variant: VARIANT_ID, // ID of the out of stock product variant about which customer wants to be notified.
        platform: "shopify", 
    },
    success: function(response){
        console.log(response)
    }
})

… and a few more.

I always got the same result:

I tried it locally as well as from the Dev environment (https://my-shopify-dev-store.myshopify.com). My Dev Klaviyo account is connected to the Shopify Development Store. 

The Development Store is only reachable by password, could this be the problem? Is there anything else I need to set up inside my Klaviyo account in order to get this working? 

Best answer by phillip

Edit: turns out that my Pi-hole blocked the request :’) It works now. 

View original
Did this topic or the replies in the thread help you find an answer to your question?

3 replies

Forum|alt.badge.img+2
  • Author
  • Problem Solver I
  • 4 replies
  • January 14, 2023

Edit: I just read somewhere else: “You do have the ability to make a front end API call to our Back in Stock endpoint.” => So what are you recommending how to call your API point? Do we need to create a Shopify App just for that?


Forum|alt.badge.img+2
  • Author
  • Problem Solver I
  • 4 replies
  • Answer
  • January 15, 2023

Edit: turns out that my Pi-hole blocked the request :’) It works now. 


Brian Turcotte
Forum|alt.badge.img+37

Hi @phillip!

 

Glad that worked out - thanks for coming back and providing the solution!

 

Best,

Brian