Home > front end >  Snipcart - error: 'product-crawling-failed'
Snipcart - error: 'product-crawling-failed'

Time:09-25

I'm trying to set up Snipcart for the first time. It seems pretty straightforward for the most part, but I'm running into some issues when I try to check out with the test payment card.

I'm working with just a vanilla front end, and Express on the back. I'm getting the same error every time:

A 'cart-confirmation' error occurred in Snipcart.

Reason: 'product-crawling-failed' 

But the URL it's returning me in my console looks like it should be able to crawl for the product properly: https://myHerokuApp.herokuapp.com/shop/starry-night

    <button class="snipcart-add-item"
        data-item-id="starry-night"
        data-item-price="79.99"
        data-item-url="/shop/starry-night"
        data-item-description="This is a sweet piece of art."
        data-item-image="img/1.jpg"
        data-item-name="The Starry Night">
        Add to cart
    </button>

I'm really confused at to what I'm doing wrong. Is there something I have to do with my express router? I've tried routing something like this just to see what would happen

router.get("/shop/:product", function (req, res, next) {
  res.json({
    "data-item-id": "starry-night",
    "data-item-price": "79.99",
    "data-item-url": "/shop/starry-night"
  })
 });

But that didn't make a difference.

I'm really hoping someone can spot what I'm doing wrong or point me in the right direction in the docs..

Thank you!

CodePudding user response:

Attributes data-item-id and data-item-price are used with HTML crawler and are defined inside buy-button.

If you want to use JSON crawler, then you should return valid JSON with properties id and price. Also, price should be of type number. Change your backed like this:

router.get("/shop/:product", function (req, res, next) {
  res.json({
    "id": "starry-night",
    "price": 79.99
  })
});

Note: your server must be publicly available (not running in your localhost).

  • Related