Skip to main content
Contributor II
February 6, 2024
Solved

Custom Back in-stock for products

  • February 6, 2024
  • 4 replies
  • 246 views

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?

    This topic has been closed for replies.
    Best answer by Maxbuzz

    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",

     

    4 replies

    MaxbuzzAnswer
    Partner
    February 7, 2024

    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",

     

    https://theforms.pro
    nalindadAuthor
    Contributor II
    February 7, 2024

    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

    Partner
    February 7, 2024

    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.

    https://theforms.pro
    nalindadAuthor
    Contributor II
    February 7, 2024

    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!