InternalServerError: Failed To Make Shopify HTTP Request: FetchError: Invalid Json Response Body

InternalServerError: Failed To Make Shopify HTTP Request: FetchError: Invalid Json Response Body

nabeelsidd
Shopify Partner
2 0 1

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:

  1. As per this post: InternalServerError with Shopify Node API I tried to set the SHOPIFY_API_VERSION variable to the following values: ApiVersion.July21, ApiVersion.October21, ApiVersion.January22, ApiVersion.April22, ApiVersion.Unstable, '2021-07', '2021-10', '2022-01', '2022-04', 'unstable' but none of them worked
  2. I tested the following version of '@shopify/shopify-api': 3.0.1, 3.0.0, 2.1.0 but all of them gave me the same error
  3. I put the app into a container and built it with GCP Cloud Build and pushed it to GCP Cloud Run and it gave me the same error as above
  4. I tried to run the GraphQL query in Shopify GraphiQL App and it works fine

Any ideas on what could be causing this error?

 

Thanks!

Replies 2 (2)

Alan
Shopify Staff
129 15 24

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

davidbittonmbp
Visitor
1 0 0

Did you ever getting it working?