Issue: A developer encountered a 400 status error when attempting to fetch products using GraphQL queries through Shopify CLI, despite following tutorial instructions.
Initial Troubleshooting Attempts:
Verified authentication setup in shopify.server.js file
Confirmed the query worked in the Shopify GraphQL app but failed in the actual code
Tested mutations successfully, ruling out broader authentication issues
Investigated environment variables and token configuration in shopify.app.toml
Root Cause & Resolution:
The problem was identified as incorrect query string formatting. The solution involved:
Using the #graphql directive at the start of the query string
Properly structuring the GraphQL query with correct syntax for nested fields (products, variants, images, selectedOptions)
Key Takeaway: The issue was not related to authentication or token validity, but rather the query string format itself. Multiple users experienced this same error, suggesting it’s a common pitfall when setting up Shopify CLI GraphQL queries.
Summarized with AI on November 15.
AI used: claude-sonnet-4-5-20250929.
I am trying to get products with GraphQL and getting the following error. I am using the Shopify CLI, I tried to follow everything in the tutorial, but I spent 6 hours trying to solve this issue. Please help! LOL.
Can you check to make sure that your access token is valid? If you’re unsure, you can regenerate a new token and replace it in your code.
Another option to troubleshoot would be to run the same query in the Shopify GraphiQL app to see if it’s working there. Depending on if it works or not you can try to rule out what’s causing this.
Been doing a bit more digging myself, in the shopify.server.js file it’s referencing process.env, so I think we may need save the token in an env file somewhere; however, some of these values seem to be automatically set in the shopify.app.toml file