1. Reference: https://shopify.dev/api/admin-graphql#authentication . All GraphQL Admin API queries require a valid Shopify access token.
2. Open the admin dashboard – Apps – Develop apps – Create a custom app. See Figure 1.

3. Enter the app name, select the app developer, and create the app. See Figure 2.

4. Configure the Admin API scopes. See Figure 3.

5. App development – Shopify access token – Configuration – Admin API integration – Select access scopes – Save. See Figure 4.

6. API credentials: You do not have any access tokens yet. To obtain an Admin API access token, install the app. Install the app. See Figure 5.

7. API credentials – Admin API access token. To protect your data, your Admin API token can only be shown once. Copy your Admin API access token and save it in a secure location. See Figure 6.

8. Reference: https://shopify.dev/api/admin-graphql#endpoints . Execute GraphQL queries by sending a POST HTTP request to the endpoint. Retrieve the IDs and titles of the three most recently added products. In Altair GraphQL Client, open a new window and enter the URL: https://xxx.myshopify.com/admin/api/2022-01/graphql.json . A login dialog box appears, as shown in Figure 7.

9. Set the Headers: Content-Type: application/graphql, X-Shopify-Access-Token: {access_token}. See Figure 8.

10. After setting the query, the response is 404. Inspecting the network requests reveals a 301 redirect to /admin/auth/login first, followed by a 302 redirect to /admin. See Figure 9.

{
products(first: 3) {
edges {
node {
id
title
}
}
}
}
11. However, when executing the query in Git Bash, the response is 200. See Figure 10.

$ curl -X POST \
> https://xxx.myshopify.com/admin/api/2022-01/graphql.json \
> -H 'Content-Type: application/graphql' \
> -H 'X-Shopify-Access-Token: shpat_' \
> -d '
> {
> products(first: 3) {
> edges {
> node {
> id
> title
> }
> }
> }
> }
> '
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 621 0 503 100 118 493 115 0:00:01 0:00:01 --:--:-- 610{"data":{"products":{"edges":[{"node":{"id":"gid:\/\/shopify\/Product\/7560274542827","title":"满送优惠测试"}},{"node":{"id":"gid:\/\/shopify\/Product\/7560295743723","title":"商品A"}},{"node":{"id":"gid:\/\/shopify\/Product\/7560318976235","title":"Apple iPhone 12 (A2404) 128GB 白色 支持移动联通电信5G 双卡双待手机"}}]}},"extensions":{"cost":{"requestedQueryCost":5,"actualQueryCost":5,"throttleStatus":{"maximumAvailable":1000.0,"currentlyAvailable":995,"restoreRate":50.0}}}}
12. Reference: https://shopify.dev/api/admin/getting-started#use-curl . If you are using an HTTP client such as Postman or Insomnia, you must set Content-Type to application/json instead of application/graphql. Reset the Headers to Content-Type: application/json. The response is still 404. After switching to a live store, the response is 200. See Figure 11.

{
products(first: 3) {
edges {
node {
id
title
}
}
}
}
{
"data": {
"products": {
"edges": [
{
"node": {
"id": "gid://shopify/Product/6944715342030",
"title": "commercial kitchen quality"
}
},
{
"node": {
"id": "gid://shopify/Product/6944715636942",
"title": "Easter Photographing Dress-up Acessories"
}
},
{
"node": {
"id": "gid://shopify/Product/6944715702478",
"title": "Perfect Pet Hair Remover"
}
}
]
}
},
"extensions": {
"cost": {
"requestedQueryCost": 5,
"actualQueryCost": 5,
"throttleStatus": {
"maximumAvailable": 1000,
"currentlyAvailable": 995,
"restoreRate": 50
}
}
}
}
13. When setting the Headers to Content-Type: application/graphql, an error occurs: Parse error on \”query\” (STRING) at [1, 2]. See Figure 12.
![When setting the Headers to Content-Type: application/graphql, an error occurs: Parse error on \"query\" (STRING) at [1, 2]](https://media.shuijingwanwq.com/2022/03/12.png)
{
"errors": [
{
"message": "Parse error on \"query\" (STRING) at [1, 2]",
"locations": [
{
"line": 1,
"column": 2
}
]
}
]
}
14. In Postman, neither of the two stores redirects. The trial store responds 200, and the live store responds 200. The trial store is accessible, and the live store is accessible. This matches expectations. See Figure 12.

Response from the trial store
{
"data": {
"products": {
"edges": [
{
"node": {
"id": "gid://shopify/Product/7560274542827",
"title": "满送优惠测试"
}
},
{
"node": {
"id": "gid://shopify/Product/7560295743723",
"title": "商品A"
}
},
{
"node": {
"id": "gid://shopify/Product/7560318976235",
"title": "Apple iPhone 12 (A2404) 128GB 白色 支持移动联通电信5G 双卡双待手机"
}
}
]
}
},
"extensions": {
"cost": {
"requestedQueryCost": 5,
"actualQueryCost": 5,
"throttleStatus": {
"maximumAvailable": 1000.0,
"currentlyAvailable": 995,
"restoreRate": 50.0
}
}
}
}
Response from the live store
{
"data": {
"products": {
"edges": [
{
"cursor": "eyJsYXN0X2lkIjo2OTQ0NzE1MzQyMDMwLCJsYXN0X3ZhbHVlIjoiNjk0NDcxNTM0MjAzMCJ9",
"node": {
"id": "gid://shopify/Product/6944715342030",
"title": "commercial kitchen quality"
}
}
],
"pageInfo": {
"hasNextPage": true,
"hasPreviousPage": false
}
}
},
"extensions": {
"cost": {
"requestedQueryCost": 3,
"actualQueryCost": 3,
"throttleStatus": {
"maximumAvailable": 1000.0,
"currentlyAvailable": 997,
"restoreRate": 50.0
}
}
}
}
15. In Git Bash, the trial store is accessible, and the live store is accessible. This matches expectations.
Response from the trial store
$ curl -X POST https://xxx.myshopify.com/admin/api/2022-01/graphql.json -H 'Content-Type: application/graphql' -H 'X-Shopify-Access-Token: shpat_' -d '
{
products(first: 3) {
edges {
node {
id
title
}
}
}
}
'
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 621 0 503 100 118 479 112 0:00:01 0:00:01 --:--:-- 593{"data":{"products":{"edges":[{"node":{"id":"gid:\/\/shopify\/Product\/7560274542827","title":"满送优惠测试"}},{"node":{"id":"gid:\/\/shopify\/Product\/7560295743723","title":"商品A"}},{"node":{"id":"gid:\/\/shopify\/Product\/7560318976235","title":"Apple iPhone 12 (A2404) 128GB 白色 支持移动联通电信5G 双卡双待手机"}}]}},"extensions":{"cost":{"requestedQueryCost":5,"actualQueryCost":5,"throttleStatus":{"maximumAvailable":1000.0,"currentlyAvailable":995,"restoreRate":50.0}}}}
Response from the live store
$ curl -X POST \
> https://fuyan666.myshopify.com/admin/api/2022-01/graphql.json \
> -H 'Content-Type: application/graphql' \
> -H 'X-Shopify-Access-Token: shpat_' \
> -d '
> {
> products(first: 3) {
> edges {
> node {
> id
> title
> }
> }
> }
> }
> '
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 604 0 486 100 118 538 130 --:--:-- --:--:-- --:--:-- 670{"data":{"products":{"edges":[{"node":{"id":"gid:\/\/shopify\/Product\/6944715342030","title":"commercial kitchen quality"}},{"node":{"id":"gid:\/\/shopify\/Product\/6944715636942","title":"Easter Photographing Dress-up Acessories"}},{"node":{"id":"gid:\/\/shopify\/Product\/6944715702478","title":"Perfect Pet Hair Remover"}}]}},"extensions":{"cost":{"requestedQueryCost":5,"actualQueryCost":5,"throttleStatus":{"maximumAvailable":1000.0,"currentlyAvailable":995,"restoreRate":50.0}}}}
16. In Postman and Git Bash, both the trial store and the live store are accessible. However, in Altair GraphQL Client, the trial store is inaccessible, and only the live store is accessible. I initially suspect this is related to manually entering the account credentials to log in when calling the trial store URL. Manual login should not be required.
