Request Shopify in Altair GraphQL ClientS GraphQL Admin API
1. Reference:https://shopify.dev/api/admin-graphql#authentication, all GraphQL Admin API queries require a valid Shopify access token.
2. Open the background – Apps – Develop applications – Create custom apps. as shown in Figure 1
3. Enter the application name, select the application developer, and create the application. as shown in Figure 2
4. Configure the background API range. as shown in Figure 3
5. Application development – Shopify access token – configuration – background API integration – select access range – save. as shown in Figure 4
6. API credentials, you do not have any access tokens. To get the background API access token, install the app. Install the app. as shown in Figure 5
7. API credentials – background API access token. To protect your data, your background API token can only be displayed once. Copy your background API access token and save it in a safe location. as shown in Figure 6
8. Reference:https://shopify.dev/api/admin-graphql#endpoints. Perform a GraphQL query by sending a POST HTTP request to the endpoint. Get the ID and title of the three recently added products. In Altair GraphQL Client, open a new window, enter the URL:https://xxx.myshopify.com/admin/api/2022-01/graphql.json, the login box will pop up, as shown in Figure 7
9. Set headers, content-type: application/graphql, x-shopify-access-token: {access_token}. as shown in Figure 8
10. After setting the query, the response is 404. To view network requests, first jump to /admin/auth/login 301, and then jump to /admin for 302. as shown in Figure 9
{
products(first: 3) {
edges {
node {
id
title
}
}
}
}
11. But the query is executed in git bash, and the response is 200. As shown in 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 the content-type to application/json and not application/graphql. Reset headers , content-type: application/json. Still responding 404. After switching to an official store, the response is 200. as shown in 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 headers, content-type: application/graphql, an error is reported: parse error on \”query\” (string) at[1, 2]. as shown in Figure 12
{
"errors": [
{
"message": "Parse error on \"query\" (STRING) at [1, 2]",
"locations": [
{
"line": 1,
"column": 2
}
]
}
]
}
14. In Postman, the two stores have not jumped, and the trial response period is 200, and the official response is 200. The trial period is available and officially available. in line with expectations. as shown in Figure 12
Responses to the store during the trial period
{
"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
}
}
}
}
Responses to the official 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 period is available and officially available. in line with expectations.
Responses to the store during the trial period
$ 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}}}}
Responses to the official 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 period and official are available. In Altair GraphQL Client, the trial period is not available, only officially available. The initial suspicion is related to manually entering the account and password to log in when the trial URL is invoked. You should not log in manually.











![当 设置 Headers ,Content-Type: application/graphql 时,报错:Parse error on \"query\" (STRING) at [1, 2]](https://www.shuijingwanwq.com/wp-content/uploads/2022/03/12.png)
