I need to filter products by the “available_for_sale” property.
It works perfectly in Postman - results are consistent and exactly as I would expect.
However, when I attempt to recreate the query in PHP, the results are incorrect. Specifically, they include a number of products which have the wrong “available_for_sale” property.
I have tried many different things to rectify the issue - using a raw cURL request to graphQL, changing the query, hardcoding everything, ensuring all of the URL / payload structure is correct, but the same thing happens.
The query I am running is as follows: -
{
products(first: 250, query: "tag:[redacted] AND product_type:[redacted] AND NOT available_for_sale:true", sortKey: TITLE, reverse: true) {
edges {
node {
handle
title
availableForSale
}
}
}
}
This code is slightly more complicated in the production/live environment, but the issue persists regardless.
The above, when run in Postman, provides a payload similar to the following:
The part that is confusing me is there is nothing different between the query I’ve been running in Postman and the one I’ve ran in PHP. Yet, the PHP request (multiple servers, using composer package and cURL) returns the same erroneous response: -
I have not tried it locally yet (will write a simple Ruby script in a few minutes) but I am extremely confused as to why it’s working perfectly in Postman and not in my PHP scripts. Is it something I have done (or not done)?
Happy to share request payloads in private.