Solved

Back In Stock API for multiple custom catalog feeds

  • 4 August 2023
  • 2 replies
  • 72 views

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?

icon

Best answer by multimerce 8 August 2023, 01:22

View original

2 replies

Userlevel 7
Badge +36

Hi @multimerce!

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

- Brian

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.

Reply