New Shopify Certification now available: Liquid Storefronts for Theme Developers

Internal error: products filters

BramK
Tourist
4 0 1

Hi all,

 

Been using the "collectionByHandle" graphql request to fetch products for the store of a client for quite a whole without problems. A couple weeks ago I added filters to this request, a bit like so:

 

 

 

 

 

products(
        first: $amount
        sortKey: $sortKey
        reverse: $reverseKey
        after: $afterCursor
        filters: { price: { min: $minPrice, max: $maxPrice } }
      )

 

 

 

 

This worked fine for quite a while, when making the request I pass on the values for minPrice and maxPrice, based on what the customer selected. This was online/live for about 1-2 weeks without any issues.

 

A couple days ago I added a filtering for product tags with the "productMetafield". This also seemed to work fine, until I put it online on my clients website. The website worked for let's say an hour (not sure how long exact), and then crashed with a 500 error. When I spinned up localhost, I got an internal error from Shopify. I figured I did something wrong, removed the "productMetafield" filter. Everything worked again. I ran a new build for the clients website, and we were back live.

 

But again, after a short while, the website crashed, 500. I spin up localhost, to spot again an internal error from Shopify. Really strange, because right now I had the price filters configuration I've had online for weeks, and now it did not work anymore. 

 

If I change the variables of "$minPrice" and "$maxPrice" by actual values in graphQL, it seems to work again. If I keep the variables, but hardcode them to number values while doing the request, the query fails with;

 

Internal error. Looks like something went wrong on our end. Request ID: 9ea1d083-e028-47a3-ad22-50f7b2f01cc4 (include this in support requests).

 

I have no clue how code that worked for 1-2 weeks, all of the sudden causes an internal error. I hope someone can help me shine some light on this. Thanks!

Replies 4 (4)
made4Uo
Shopify Partner
3787 710 1102

Hi @BramK,

 

The only thing I can think of is the request header. You might not have the right header

Volunteering to assist you!  Likes and Accept as Solution  is highly appreciated.✌
Coffee fuels my dedication. If helpful, a small Coffee Tip would be greatly appreciated.
Need EXPERIENCED Shopify developer without breaking the bank?
Hire us at Made4Uo.com for quick replies.
Stay in control and maintain your security by avoiding unnecessary store access!
BramK
Tourist
4 0 1

Hi @made4Uo ,

 

Thanks for the quick reply! This made me take a look at the webhook version inside Shopify, and it was a mismatch with the one I was using. Weird thought that even though that was a mismatch, the filtering did work for a while.

 

I've updated them to match now, version 2022-07. Will update this topic once site is live and running for several hours without issues. Thanks!

BramK
Tourist
4 0 1

Unfortunately, this was not the solution. It's very confusing. I had the product filters running on my localhost again, no problems. Clean cache, no issues. I put the website live, initially shows just fine, couple minutes later; crash. Internal server error. After that, the code gives an error locally as well, while the exact same code worked fine while testing before putting live. It's almost like the API blocks the requests after going live.

 

Headers:

import { GraphQLClient } from "graphql-request";

const endpoint = "https://myclient.myshopify.com/api/2022-07/graphql";

export const graphQLClient = new GraphQLClient(endpoint, {
  headers: {
    "X-Shopify-Storefront-Access-Token": "myaccesstoken",
    Accept: "application/json",
  },
});

 

Don't think anything is wrong there...

made4Uo
Shopify Partner
3787 710 1102

Hi @BramK,

 

It might be because of the updates. I would recommend to contact Shopify support on this. 

Volunteering to assist you!  Likes and Accept as Solution  is highly appreciated.✌
Coffee fuels my dedication. If helpful, a small Coffee Tip would be greatly appreciated.
Need EXPERIENCED Shopify developer without breaking the bank?
Hire us at Made4Uo.com for quick replies.
Stay in control and maintain your security by avoiding unnecessary store access!