Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Re: Shopify CLI GraphQL returns status 400

Shopify CLI GraphQL returns status 400

oozbasaran
Shopify Partner
7 0 1

 

 

 

export async function loader({ request, params }) {
  try {
    const { admin, session } = await authenticate.admin(request);

    const queryString = `query {
      products () {
        edges {
          node {
            id
            title
          }
        }
      }
    }`

    const response = await admin.graphql({
      data: queryString
    })
    
  } catch (error) {
    console.error("Authentication or GraphQL error:", error);
}

 

 

 

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.

oozbasaran_0-1699593694842.png


This is my configuration:

oozbasaran_1-1699593732767.png

 

 

Replies 7 (7)

Liam
Community Manager
3108 344 904

Hi Oozbasaran,

 

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.

 

Hope this helps,

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

oozbasaran
Shopify Partner
7 0 1

oozbasaran_0-1699625537686.png

 

My shopify.server.js file is like the above. Does not it handle the Auth automatically?

 

oozbasaran
Shopify Partner
7 0 1

The query is working in the Shopify GraphQL app, but not in my code, I tried a mutation and it is working in my code, but not the query.

carecare
Shopify Partner
13 3 7

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

 

This however, is still giving me a 400 error

carecare
Shopify Partner
13 3 7

I'm having the same error:

In an app set up with Shopify CLI, a simple graphql query (near identical format to OP) is returning a 400.

 

This set up seems to match the docs, so any input on how to get a simple query running in a shopify app would be a huge help.

 

Thanks!

carecare
Shopify Partner
13 3 7

Hi there! I played around with this some more and ultimately found that the issue was with my query string. This ended up working for me:

`#graphql
      query getProducts{
      products(first: 10, reverse: true) {
        edges {
          node {
            id
            title
            handle
            images(first: 1) {
              edges {
                node {
                  originalSrc
                }
              }
            }
            variants(first: 1) {
              edges {
                node {
                  price
                  selectedOptions {
                    name
                    value
                  }
                }
              }
            }
          }
        }
      }
    }`
Liam
Community Manager
3108 344 904

Great to hear this is working for you! Thanks for posting up your solution!

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog