Skip to main content
multimerce
Partner - Gold
Partner - Gold
August 4, 2023
Solved

Back In Stock API for multiple custom catalog feeds

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?

This topic has been closed for replies.
multimerce
Partner - Gold
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.

2 replies

Brian Turcotte
Klaviyo Alum
August 7, 2023

Hi @multimerce!

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

- Brian

multimerce
Partner - Gold
multimerceAuthorAnswer
Partner - Gold
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.