A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
I'm using the shopify-node-api (v 3.0.1) and trying to make a basic GraphQL call with the following code:
const { Shopify, ApiVersion } = require('@shopify/shopify-api');
Shopify.Context.initialize({
API_KEY: <KEY REMOVED>,
API_SECRET_KEY: <SECRET REMOVED>,
SCOPES: 'write_products,write_orders,read_all_orders,write_price_rules,read_inventory',
HOST_NAME: <HOST REMOVED>,
IS_EMBEDDED_APP: true,
SHOPIFY_API_VERSION: '2021-10'})
const shopifyClient = new Shopify.Clients.Graphql('test-store.myshopify.com', <ACCESS TOKEN REMOVED>)
await shopifyClient.query({data: `query {shop {currencyCode currencyFormats {moneyFormat}}}`,});
and getting the error:
HttpRequestError: Failed to make Shopify HTTP request: FetchError: invalid json response body at https://test-store.myshopify.com/admin/api/undefined/graphql.json reason: Unexpected end of JSON input
at HttpRequestError.ShopifyError [as constructor] (/truncated-path/node_modules/@shopify/shopify-api/dist/error.js:13:28)
at new HttpRequestError (/truncated-path/node_modules/@shopify/shopify-api/dist/error.js:79:42)
Note: I've truncated the code paths above to make it easier to read.
Things I've tried that didn't work:
Any ideas on what could be causing this error?
Thanks!
Hey @nabeelsidd - thanks for getting in touch and for your patience here, it's really appreciated. This was a great question and I was able to do a little digging into this on my end for you.
Usually, those ....myshopify.com/admin/api/undefined response messages originate out of incorrect API version references in the initial API call. I was able to do some testing myself and replicated a bit of the code snippet provided using Node on my end, but replaced the "SHOPIFY_API_VERSION" value with just "API_Version".
Here, you could then use the referenced syntax for API versions (I'd recommend using our most recent release, April 2022). The correct syntax used to reference the API Version would look like this:
API_VERSION: ApiVersion.April22});
I'm confident this should help - cheers!
Alan | API Support @ Shopify
- Was my reply helpful? Click Like to let me 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
Did you ever getting it working?