What's your biggest current challenge? Have your say in Community Polls along the right column.
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: Storefront API - content-type: application/graphql gives parse error

Solved

Storefront API - content-type: application/graphql gives parse error

drewrbaker
Visitor
2 0 4

I'm just trying to follow the basic example of the Storefront API, and it seems if I set `Content-Type` to `application/graphql` (see screenshots) it gives me this error:

{
  "errors": [
    {
      "message": "Parse error on \"query\" (STRING) at [1, 2]",
      "locations": [
        {
          "line": 1,
          "column": 2
        }
      ]
    }
  ]
}

Now if I set `Content-Type` to `application/json` it seems to work, but then I can't get it to return any product or collection data. Is this a documentation error or am I doing something something basic wrong here?

 

Screen Shot 2019-07-30 at 7.47.36 PM.pngScreen Shot 2019-07-30 at 7.48.00 PM.png

Accepted Solution (1)

Ryan
Shopify Staff
499 42 120

This is an accepted solution.

Hi @drewrbaker,

 

For the most part with any HTTP client or library you would use application/json.  Setting the header to application/graphql means to explicitly treat the HTTP POST body as the contents of a GraphQL query string, so the format you are passing is invalid.  See https://graphql.org/learn/serving-over-http/ for a little more explanation.

 

To get more collection or product data you would need to add more query parameters to the query you are making.  All you are requesting is the id and handle.  Check our documentation for all the possible parameters.

Ryan | 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 the Shopify Help Center or the Shopify Blog

View solution in original post

Replies 5 (5)

Ryan
Shopify Staff
499 42 120

This is an accepted solution.

Hi @drewrbaker,

 

For the most part with any HTTP client or library you would use application/json.  Setting the header to application/graphql means to explicitly treat the HTTP POST body as the contents of a GraphQL query string, so the format you are passing is invalid.  See https://graphql.org/learn/serving-over-http/ for a little more explanation.

 

To get more collection or product data you would need to add more query parameters to the query you are making.  All you are requesting is the id and handle.  Check our documentation for all the possible parameters.

Ryan | 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 the Shopify Help Center or the Shopify Blog

drewrbaker
Visitor
2 0 4

Thanks Ryan. I'd recommend you update the docs about using application/json, it tripped us up for awhile. Thanks!

MozzoERP
Shopify Partner
84 4 20

@drewrbaker @Ryan 

Yes!!! This same documentation issue caused us to waste days! Please update ASAP!

The documentation in question is here. It shows the Content-Type as application/graphql, but for client tool posting, it should be application/json.

Chad Richardson
Mozzo Software - Modular Software that grows with you from solopreneur to a 200 person mega team. Why keep outgrowing your Shopify Apps? Start with us, and just use the modules you need, then add more as you grow. http://MozzoERP.com
Ryan
Shopify Staff
499 42 120

@MozzoERP It needs to be application/graphql for CURL like the example says.  I will mention to the docs team that we can add a note about HTTP clients requiring application/json.

Ryan | 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 the Shopify Help Center or the Shopify Blog

Drg732
Visitor
2 0 1

Just a reminder to update the documentation. This also gave me a hard time.