Solved

Custom Back in-stock for products

  • 6 February 2024
  • 4 replies
  • 50 views

Badge

Hi

I need to run back in stock subscription in some of the products regardless of the stock availability. Can I run bellow script in my website. and add item to back in stock for custom use? 

$.ajax({
    type: "POST",
        ur: "https://a.klaviyo.com/onsite/components/back-in-stock/subscribe",
        data: {
        a: "public-api",
        email: "useremail@gmail.com",
        variant: "55005964218416-variant-id",
        platform: "shopify"
    },
    success: function(response){
        console.log(response)
    }
    })

When I run this script in chrome dev tool (with actual data) it returns 404 (Not Found), what is the issue?

icon

Best answer by Maxbuzz 7 February 2024, 05:52

View original

4 replies

Userlevel 3
Badge +7

Hi

I need to run back in stock subscription in some of the products regardless of the stock availability. Can I run bellow script in my website. and add item to back in stock for custom use? 

$.ajax({
    type: "POST",
        ur: "https://a.klaviyo.com/onsite/components/back-in-stock/subscribe",
        data: {
        a: "public-api",
        email: "useremail@gmail.com",
        variant: "55005964218416-variant-id",
        platform: "shopify"
    },
    success: function(response){
        console.log(response)
    }
    })

When I run this script in chrome dev tool (with actual data) it returns 404 (Not Found), what is the issue?

 

Try changing
ur: "https://a.klaviyo.com/onsite/components/back-in-stock/subscribe",

to 
url: "https://a.klaviyo.com/onsite/components/back-in-stock/subscribe",

 

Badge

Thanks @Maxbuzz ,

 

It is working, thanks for finding the typo :) 

Is there anyway I can pass the user email consent with this?

 

Thanks again!

Nalinda

Userlevel 3
Badge +7

Thanks @Maxbuzz ,

 

It is working, thanks for finding the typo :) 

Is there anyway I can pass the user email consent with this?

 

Thanks again!

Nalinda

According to this documentation, we can only pass the the already used 4 values.

Badge

Below is the new API call for back in stock, seems working, but will have to call different API call to subscribe same user to a list. But not sure how it works

 

const payload = {    "data": {        "type": "back-in-stock-subscription",        "attributes": {            "profile": {                "data": {                    "type": "profile",                    "attributes": {                        "email": "nutsynalinda@gmail.com",                    }                }            },            "channels": ["EMAIL"],        },        "relationships": {            "variant": {                "data": {                    "type": "catalog-variant",                    "id": "$shopify:::$default:::VAR_ID".toString(),                }            }        }    }}var requestOptions = {    method: 'POST',    headers: {        "Content-Type": "application/json",        "revision":"2023-12-15"    },    body: JSON.stringify(payload),};fetch("https://a.klaviyo.com/client/back-in-stock-subscriptions/?company_id=XXPUBLICIDXXX",requestOptions)    .then(result => console.log(result))    .catch(error => console.log('error', error));

 

 

Thank you!

Reply