Focuses on API authentication, access scopes, and permission management.
We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more
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 } } }, }" }'
Solved! Go to the solution
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
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
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.
Thanks @designbygio - can you point me to where you can across this example in the docs?
Scott | Developer Advocate @ Shopify