Skip to main content
Contributor I
Jun 6, 2024 11:16 PM UTC
Solved

Shopify: Back in Stock via API not working

Hello, I am new to Klaviyo and I would like to make a back in stock API call out of my Shopify store, like explained here. I do not understand the error: is my products do not have a variant, only a product ID. And maybe I miss understood the concept of a relationship. I thought I am creating one by assigning a product to a profile by this query. Maybe someone can help me.

# URL
url = "https://a.klaviyo.com/client/back-in-stock-subscriptions/?company_id=myID"

# Body
body = {
"data": {
"type": "back-in-stock-subscription",
"attributes": {
"profile": {
"data": {
"type": "profile",
"attributes": {
"email": "email@mail.com"
}
}
},
"channels": ["EMAIL"]
},
"relationships": {
"product": {
"data": {
"type": "catalog-variant",
"id": "$shopify:::$default:::productID"
}
}
}
}
}

 

I get the error code:

Response Text: {"errors":[{"id":"dfae79b0-0dd5-46e4-9b3c-7906e4ed4280","status":404,"code":"variant_not_found","title":"The variant in your relationship payload does not exist","detail":"The variant in your relationship payload does not exist","source":{"pointer":"/data/relationships/variant/data/id"},"links":{},"meta":{}}]}

This topic has been closed for replies.
Kim Strauch
Klaviyo Employee
Jun 21, 2024 6:56 PM UTC

Hey @ITgirl, the error you’re getting is because you’re using the product ID instead of the variant ID. I believe even in the case where you don’t have multiple variants configured for Shopify there is a default variant ID that can be obtained. 

We have a recommended way to install Back in Stock using a JS widget detailed on our Help Center here: https://help.klaviyo.com/hc/en-us/articles/360001895651.This way, Klaviyo.js handles some of the heavy lifting around determining the variant ID, whether the item is in stock or out of stock and what the variant ID is.
 

If you’re trying to wire this up yourself using the client API directly….

const variantId = document.querySelector('[name="id"]').value

4 replies

kaila.lawrence
Community Manager
Community Manager
Jun 18, 2024 6:47 PM UTC

@ITgirl I am SO sorry for the late reply here. You post was mistakenly flagged as spam by our system. I’m investigating why further. 

In the meantime, did you get this figured out?

ITgirlAuthor
Contributor I
Jun 18, 2024 9:25 PM UTC

Hello @kaila.lawrence,

no problem. No, not yet.

Kim Strauch
Klaviyo Employee
Klaviyo Employee
Jun 21, 2024 6:56 PM UTC

Hey @ITgirl, the error you’re getting is because you’re using the product ID instead of the variant ID. I believe even in the case where you don’t have multiple variants configured for Shopify there is a default variant ID that can be obtained. 

We have a recommended way to install Back in Stock using a JS widget detailed on our Help Center here: https://help.klaviyo.com/hc/en-us/articles/360001895651.This way, Klaviyo.js handles some of the heavy lifting around determining the variant ID, whether the item is in stock or out of stock and what the variant ID is.
 

If you’re trying to wire this up yourself using the client API directly….

const variantId = document.querySelector('[name="id"]').value

ITgirlAuthor
Contributor I
Aug 12, 2024 3:36 PM UTC

Thank you, that helped!