Have your say in Community Polls: What was/is your greatest motivation to start your own business?
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: Simple query returns 400 bad request and no indication of error

Solved

Simple query returns 400 bad request and no indication of error

plopify
Shopify Partner
7 0 0

Hi,

 

Newbie to GraphQL. I have a basic query working, for example to show the first 100 product titles:

 

{"query": "{products(first:100){edges{node{title}}}}"}

 

However, I've had no luck with any type of query to search a product. My current (failing) query is as follows - searching for a wildcarded piece of text and returning the first node and its title:

 

{"query": "{products(first:1, query:"title:Brace*"){edges{node{title}}}}"}

 

This results in Error 400, Bad Request. Appreciate a heads-up on what's wrong with the above query. My content header and access key are all ok since the first query works ok.

Thanks in advance.

Accepted Solution (1)
gojiberry-des
Shopify Partner
29 7 5

This is an accepted solution.

You need to use double quotes for your products query.

Try this:

{"query":"{products(first:100,query:\"title:*brace*\"){edges{node{title}}}}"}

 

If you like my suggestion please give it a LIKE or mark it as a solution! ★★★★★

Gojiberry - Best post-purchase survey and feedback app for Shopify | Install on App Store for free
Shopify Community is helpful, BUT... why not start asking your customers for feedback instead?

View solution in original post

Replies 4 (4)

DaveedValencia
Shopify Partner
43 7 7

Hello,

 

You have syntax errors in your code, below is proper syntax to achieve this. Let me know if you have any more questions!

query {
  products(first:100,query:"title:*brace*"){
    edges{
      node{
        title
      }
    }
  }
}

 

plopify
Shopify Partner
7 0 0

Daveed, thanks for the reply.

 

I think quotes are my problem. I now see this:

 

{"errors":[{"message":"syntax error, unexpected invalid token (\"'\") at [1, 27]","locations":[{"line":1,"column":27}]}]}

 

Can I use single quotes around the query, like this?

{"query":"{products(first:100,query:'title:*brace*'){edges{node{title}}}}"}

 

If I use a double quote, it breaks. I am escaping my second lot of quotes also, but should I need to? Is there an alternative syntax for the query() ?

 

gojiberry-des
Shopify Partner
29 7 5

This is an accepted solution.

You need to use double quotes for your products query.

Try this:

{"query":"{products(first:100,query:\"title:*brace*\"){edges{node{title}}}}"}

 

If you like my suggestion please give it a LIKE or mark it as a solution! ★★★★★

Gojiberry - Best post-purchase survey and feedback app for Shopify | Install on App Store for free
Shopify Community is helpful, BUT... why not start asking your customers for feedback instead?

plopify
Shopify Partner
7 0 0

This worked in the end:

{"query":"{products(first:10,query:\"title:*brace*\"){edges{node{title}}}}"}

I had to use \ to escape. I think the issue is my platform/environment. Thanks for nudging me along; I have a solution now at least 👍