A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
We develop an app that uses the Shopify API to help our customers track who has ordered swag from their internal Shopify stores.
We are running into an issue with exactly one customer in which the GraphQL API is not working. I can reproduce this issue very consistently no matter how I query the GraphQL API (using the Node.js SDK, using cURL on the command line, using Postman to make requests, etc). The error only occurs for this one customer, and not for our other customers. The error only occurs when using the GraphQL API; there are no errors with the REST API.
For the purposes of this post, I am going to use the Node.js SDK to demonstrate the error.
const shopify = shopifyApi({
apiSecretKey: '...',
apiVersion: ApiVersion.April23,
isCustomStoreApp: true,
adminApiAccessToken: '...',
isEmbeddedApp: false,
hostName: 'SHOPNAME.myshopify.com',
restResources,
});
const session = shopify.session.customAppSession('SHOPNAME.myshopify.com');
const client = new shopify.clients.Graphql({ session });
const queryString = `{
shop {
name
}
}`;
const response = await client.query({ data: queryString });
console.log(response);
For one of our customers, this code is consistently failing with:
[shopify-api/INFO] version 7.3.1, environment Node v18.16.0
Error: Received an error response (404 Not Found) from Shopify:
"Not Found"
If you report this error, please include this id: 8526b80d-4df6-46f9-8a08-6b6248d431e3
Summarizing some of what I've already tried:
Is there a way that someone on the Shopify support team can use the ID in the above error message to help me figure out what's going on, and how to fix it? Thanks.
Solved! Go to the solution
This is an accepted solution.
I left a long reply that appears to have been deleted, or is otherwise now missing from this thread. Since that reply, I have an update.
I have now solved this on my own. The 301 redirect was in fact the culprit here.
If I make requests directly to the subdomain in the 301 response's location header, then the API works as expected for this shop.
So to recap, the problem was two-fold:
(1) I tried to use the shopify-api-js SDK to help your team reproduce the error, but unfortunately, that SDK is buggy and was incorrectly sending GET requests.
(2) Even when correctly sending POST requests, one particular shop was consistently failing with errors. Using cURL, I was able to inspect the response headers from the Admin GraphQL API requests for this shop and saw that every GraphQL response started with a 301 redirect. Updating our code to use the subdomain pointed to by this redirect resolved the issue.
Hey @jhurwitz,
Thanks for sharing details and troubleshooting in your post. I was able to use the provided x-request-id (8526b80d-4df6-46f9-8a08-6b6248d431e3) to locate logs for the request.
After more testing, if you feel there is still unexpected behavior involving the shopify-api-js library; I'd encourage logging more request/response data (eg. headers, timeframe, method, errors) and consider opening an issue in the official Github repo here. Otherwise, you are welcome to post any API library specific questions in our new forum board here: Shopify CLI and Tools.
Hope this helps with troubleshooting - cheers!
@awwdam | Shopify Developer Support
Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog
Thanks for the quick response. We're not using the shopify-api-js library in our production codebase. I had read conflicting instructions online about what headers to include in Admin GraphQL API calls, so I thought that using the shopify-api-js library would be the best way to report an easily reproducible bug to your team. I now see that I'm mistaken.
In our codebase, we are using no SDKs and are hitting the GraphQL endpoint directly. I'm still seeing a bug when we do this. It's admittedly a slightly different one (the response back is not the 404 Not Found), but there does still seem to be something wrong with this one single customer/this specific store.
Let me demonstrate using cURL requests that I know for a fact are sending POST requests.
Here are several different permutations of cURL requests with slightly different headers/arguments, and the results they return back on my own store, and on the store for the specific customer for whom we're seeing issues. I've also annotated each with the x-request-id response header.
The following are demonstration-only GraphQL queries. We are not running any of these in production, but I thought that fetching the shop name and nothing else would be a good way to test auth via cURL.
(1) Content type JSON, --data-raw parameter. Works only in my own shop, but not on the customer's shop.
curl -L -i -X POST 'https://SHOPNAME.myshopify.com/admin/api/2023-04/graphql.json' \
-H 'X-Shopify-Access-Token: ...' \
-H 'Content-Type: application/json' \
--data-raw '{"query":"{ shop { name }}"}'
On my own store, the x-request-id is 3c983672-ef13-487b-9507-eee9f4d4ffda and the behavior is a 200 response with valid data.
On the store for the customer facing issues, the first response is a 301 redirecting to a different subdomain (the location header in the response is location: https://AUTOGENERATEDSHOPNAME.myshopify.com/admin/api/2023-04/graphql.json after I made an initial request to the user-selected shop name) with an x-request-id for this first response of dfb8e0f4-7c64-4b96-96e4-ef2666e86eb9. After the 301 redirect, the second response is a 400 response with an x-request-id of 6974628c-b2fc-474c-aa8f-36c349e73ce6 and a body of {"errors":{"query":"Required parameter missing or invalid"}}.
(2) Content type JSON, --data parameter. Works only in my own shop, but not on the customer's shop.
curl -L -i -X POST 'https://SHOPNAME.myshopify.com/admin/api/2023-04/graphql.json' \
-H 'X-Shopify-Access-Token: ...' \
-H 'Content-Type: application/json' \
-d '{"query":"{ shop { name }}"}'
On my own store, the x-request-id is 884c854f-11f7-48ed-ac17-8c2e31cb1c48 and the behavior is a 200 response with valid data.
On the store for the customer facing issues, I see a similar 301-then-400 pattern. The x-request-id of the first response is 9bce450d-5528-4eaa-b318-cbdc80e8257d and of the second is 82681d43-0797-4362-bbf5-5575ab729344. The response body is the same error as before.
(3) Content type GraphQL, --data-raw parameter. Does not work in either shop.
curl -L -i -X POST 'https://SHOPNAME.myshopify.com/admin/api/2023-04/graphql.json' \
-H 'X-Shopify-Access-Token: ...' \
-H 'Content-Type: application/graphql' \
--data-raw '{"query":"{ shop { name }}"}'
On my own store, the x-request-id is 8a57e8f6-002e-4183-adfd-95249484e518 and the behavior is a 200 response returning an error:
{"errors":[{"message":"Parse error on \"query\" (STRING) at [1, 2]","locations":[{"line":1,"column":2}]}]}%
On the store for the customer facing issues, I see a similar 301-then-400 pattern. The x-request-id of the first response is 7dd4471a-0609-4ef5-a64c-f9fff10999bf and of the second is 41787734-260c-4b97-b6ba-831936cebd6e. The response body is the same error as before, {"errors":{"Body missing or invalid":"Required parameter missing or invalid"}}.
(4) Content type GraphQL, --data parameter. Does not work in either shop.
curl -L -i -X POST 'https://SHOPNAME.myshopify.com/admin/api/2023-04/graphql.json' \
-H 'X-Shopify-Access-Token: ...' \
-H 'Content-Type: application/graphql' \
-d '{"query":"{ shop { name }}"}'
On my own store, the x-request-id is b1b981f7-ab01-419e-9484-bb5352a89b09 and the behavior is a 200 response returning an error:
{"errors":[{"message":"Parse error on \"query\" (STRING) at [1, 2]","locations":[{"line":1,"column":2}]}]}%
On the store for the customer facing issues, I see a similar 301-then-400 pattern. The x-request-id of the first response is 37fb3b0e-73a7-4818-b2b5-5d5851484a60 and of the second is 827f9b50-e1e1-41f6-81b0-f954781bbf55. The response body is the same error as before, {"errors":{"Body missing or invalid":"Required parameter missing or invalid"}}.
In summary, even with a POST request (such that we are not hitting the 404 Not Found error caused by using the official SDK), there is still something broken for this one particular customer/one shop. I suspect it has something to do with the 301 redirect that we are seeing only for this store and not for other stores.
This is an accepted solution.
I left a long reply that appears to have been deleted, or is otherwise now missing from this thread. Since that reply, I have an update.
I have now solved this on my own. The 301 redirect was in fact the culprit here.
If I make requests directly to the subdomain in the 301 response's location header, then the API works as expected for this shop.
So to recap, the problem was two-fold:
(1) I tried to use the shopify-api-js SDK to help your team reproduce the error, but unfortunately, that SDK is buggy and was incorrectly sending GET requests.
(2) Even when correctly sending POST requests, one particular shop was consistently failing with errors. Using cURL, I was able to inspect the response headers from the Admin GraphQL API requests for this shop and saw that every GraphQL response started with a 301 redirect. Updating our code to use the subdomain pointed to by this redirect resolved the issue.