Skip to main content
Solved

Shopify: Back in Stock via API not working


Forum|alt.badge.img+1

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":{}}]}

Best answer by Kim Strauch

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

View original
Did this topic or the replies in the thread help you find an answer to your question?

4 replies

kaila.lawrence
Community Manager
Forum|alt.badge.img+31

@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?


Forum|alt.badge.img+1
  • Author
  • Contributor I
  • 0 replies
  • June 18, 2024

Hello @kaila.lawrence,

no problem. No, not yet.


Kim Strauch
Klaviyo Employee
Forum|alt.badge.img+9
  • Klaviyo Employee
  • 91 replies
  • Answer
  • June 21, 2024

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


Forum|alt.badge.img+1
  • Author
  • Contributor I
  • 0 replies
  • August 12, 2024

Thank you, that helped!