Admin API request work with REST but not with GraphQL

Solved

Admin API request work with REST but not with GraphQL

designbygio
Shopify Partner
2 0 0

I am trying to get my first 3 products with Admin API.
I tested with cURL and Postman and I can get the products with REST but not with GraphQL query.
I tested the query in the Shopify GraphiQL App, and it works fine. So it should not be a problem with the query syntax. It should not be a problem with the API Key; otherwise REST will not work either.
What can it be??

cURL return "Bad Request 443" weather Postman return

"errors": "[API] Invalid API key or access token (unrecognized login or wrong password)"


Here is my working REST cURL

 
curl -X GET \
-H "Content-Type: application/json" \
-H "X-Shopify-Access-Token: MY_ADMIN_API_KEY" \
"https://my-store-name.myshopify.com/admin/api/2023-10/products.json?limit=3"

 

and here the NOT working GraphQL cURL:

curl -X POST   https://my-shop-name.myshopify.com/admin/api/2023-10/graphql.json \
  -H 'Content-Type: application/json' \
  -H 'X-Shopify-Access-Token: MY_API_KEY' \
  -d '{
  "query": "{
    products(first: 3) {
        edges {
          node {
            id
            title
          }
        }
    },
  }"
}'

I have seen other similar issues in this forum and in Stackoverflow, but nothing that can help me.
Any tips would be highly appreciated!
Accepted Solution (1)

SBD_
Shopify Staff
1829 271 414

This is an accepted solution.

Hey @designbygio 

 

Looks like curl is having a hard time with the new lines in the JSON.

 

Try:

https://{shop}.myshopify.com/admin/api/2021-07/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {token}' \
-d '{"query": "{ products(first: 3) { edges { node { id title } } } }"}'

Scott | Developer Advocate @ Shopify 

View solution in original post

Replies 3 (3)

SBD_
Shopify Staff
1829 271 414

This is an accepted solution.

Hey @designbygio 

 

Looks like curl is having a hard time with the new lines in the JSON.

 

Try:

https://{shop}.myshopify.com/admin/api/2021-07/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {token}' \
-d '{"query": "{ products(first: 3) { edges { node { id title } } } }"}'

Scott | Developer Advocate @ Shopify 

designbygio
Shopify Partner
2 0 0

Hey @SBD_ thank you very much for your quick reply. And indeed you were right, the above command works!
It would be great if Shopify team knows about it and update GraphQL cURL documentation examples.

SBD_
Shopify Staff
1829 271 414

Thanks @designbygio  - can you point me to where you can across this example in the docs?

Scott | Developer Advocate @ Shopify