Skip to main content
Solved

Back In Stock API for multiple custom catalog feeds


multimerce
Partner - Gold

Hi, we’re trying to subscribe users to BiS (Back in stock) via API, however, it’s not working.

We have 100+ custom catalog sources, so our code specifies which catalog and variant to match. The variable “studio” matches the correct catalog, in this case “Example” will match catalog https://www.klaviyo.com/catalog/sources/31134

input:

email: example@website.com

variant: 12345

platform: api

a: ABCDE

studio: Example

 

code:

const url = "https://a.klaviyo.com/onsite/components/back-in-stock/subscribe";

const studioToId = {
  "Example": "31134",
  "Example1": "31135",
  "Example2": "31136",
  // Continue list here
};

const id = studioToId[inputData.studio];

const data = new URLSearchParams({
    a: inputData.a,
    email: inputData.email,
    variant: `$custom:::${id}:::${inputData.variant}`,
    platform: inputData.platform
}).toString();

fetch(url, {
    method: "POST", 
    headers: {
        "Content-Type": "application/x-www-form-urlencoded"
    },
    body: data
})
.then(response => response.json())
.then(data => {
    console.log(data);
    callback(null, data);
})
.catch((error) => {
    console.error('Error:', error);
    callback(error);
});
 


My hint is that the issue is in how we format $custom:::${id}:::${inputData.variant} but I have limited knowledge here.

Any help?

Best answer by multimerce

Hi @Brian Turcotte .

All good, I was able to fix the code. I split the code in two parts:

  1. Assigned the correct studioToId and returned as a new input variable
  2. Fired the BiS separately and it worked.
View original
Did this topic or the replies in the thread help you find an answer to your question?

2 replies

Brian Turcotte
Forum|alt.badge.img+37

Hi @multimerce!

I’m going to check with Engineering on this one and I’ll update the thread shortly!
 

- Brian


multimerce
Partner - Gold
  • Author
  • Partner - Gold
  • 4 replies
  • Answer
  • August 7, 2023

Hi @Brian Turcotte .

All good, I was able to fix the code. I split the code in two parts:

  1. Assigned the correct studioToId and returned as a new input variable
  2. Fired the BiS separately and it worked.