Trying just a basic GraphQL Request using Postman, always getting a malformed syntax error

Solved
Highlighted
Tourist
7 2 1

Attempting to build a public app. Can't seem to get graphQL working at all, always receiving a 400 response -- malformed syntax error even copying and pasting the most simple example graphQL queries:

{
  shop {
    name
  }
}

Also tried 

query {
  shop {
    name
  }
}

Request type is set to GET

I have selected GraphQL in the Body tab, also tried raw

I believe the proper URL is:

https://{shop}/api/graphql

But I've also tired
https://{shop}/admin/api/graphql.json
https://{shop}/admin/api/graphql

Obviously replacing {shop} with my shop's domain

I am including headers:
X-Shopify-Access-Token -- tried filled out with the token I've gotten back from OAuth and my app's private api key
Content-Type of application/graphql (also tried application/json)

I've searched all around for about 3 hours, on these forums, stackoverflow, general google searches, watched the shopify partners video on youtube about using graphql and I still can't get any different response than malformed syntax error

0 Likes
Highlighted
Pathfinder
83 4 8

The way I got this up and running is following this: 

https://shopify.dev/tutorials/build-a-shopify-app-with-node-and-react/learn-the-graphql-admin-api

Did you try that yet? 

Another helpful link if you haven't seen it yet: 

https://www.shopify.com/partners/blog/shopify-graphql-learning-kit 

 

0 Likes
Highlighted
Tourist
7 2 1

Yes I've seen that tutorial and the graphQL query I'm attempting is even more simple than the example in that link. I tried copying that exact query in the link and again malformed syntax error.

 

I guess I will try Insomnia, I'm not sure how it's different than using postman though, I've basically followed the same steps using postman.

0 Likes
Highlighted
Pathfinder
83 4 8

If you want to just get a basic GraphQL example working, follow that react node tutorial and set up your graphql how it is described. You probably are missing some underlying fundamentals which are setup properly when you walk through as described. 

0 Likes
Highlighted
Tourist
7 2 1

I'm not even calling this from my app, I'm trying to use Postman...

Also I followed the insomnia tutorial, which is just for private apps, and I am attempting to build a public app, but filled in information with my access token that I got after OAuth and my app's private api key just to try, and getting "Got status 401 fetching schema" on the Run the test query part...

0 Likes
Highlighted
Tourist
7 2 1

This is an accepted solution.

For anyone needing help with this for a public app, I figured out the proper configuration:

POST request (this is the main part that I had wrong)

URL is https://{shop}/admin/api/graphql.json (I had assumed wrong based on other examples I saw)

Headers:

X-Shopify-Access-Token has to be the value you received back from OAuth, NOT the private API key

Content-Type has to be application/json, NOT application/graphql

In the Body:

Schema of GraphQL

Using Query in the body does not matter, you can use it or omit it

 

1 Like
Highlighted
Tourist
7 2 1

I figured it out, but to expand in case anyone else needs the help - 

  • That first link focuses on private apps, in the case of a private app you need to use the Admin API Password from the Shopify Partner back end for your app as the X-Shopify-Access-Token
  • The second link talks about using a Content-Type of application/graphql, I found that this is possible using Postman, but you have to change the Body schema to raw, you cannot use the schema of GraphQL together with that application/graphql Content-Type
    • I had found this answer previously, and was part of my confusion in finding the proper configuration for things working together
0 Likes
Highlighted
Tourist
7 2 1

This is an accepted solution.

I wanted to expand on this more to try to help other people out -

The correct URL to use is NOT  https://{shop}.myshopify.com/admin/api/graphql.json - as stated in multiple posts on these forums by people from Shopify - this will default to the oldest available graphql version - April 2019 - which is not supported and not accurate anymore, and fields you expect to exist will be missing.

 

You should use https://{shop}/admin/api/2020-07/graphql.json - you must include the graphql version - this is the current stable release, there is also 2020-10 which is a release candidate

 

 

0 Likes