Solved

Admin REST API GET request returns absolutely nothing

artooras
Shopify Partner
24 0 11

I am builing a public app with Next.js, and I am observing a really strange behaviour which I am not able to debug. I have implemented the code to verify theme support for app blocks following the official example.

 

If you look at the example code, there are 4 places where the code calls Admin REST API calls:

  • Get all themes.
  • Get all assets for a theme.
  • Get a specific asset.
  • Get a specific asset (again, but with a different input).

 

I created a wrapper method for the REST call so that I can log more conveniently. This is how it looks:

 

const rest = async (shop: string, accessToken: string, data: GetRequestParams): Promise<any> => {

  const client = new Shopify.Clients.Rest(shop, accessToken)

  try {

    console.log('__REST_GET ' + JSON.stringify(data));
    return await client.get(data as GetRequestParams).then(res => {
      console.log('__REST_RESPONSE ' + JSON.stringify(data) + ' ' + res.body);
      return res.body
    }).catch(handleError)

  } catch (e) {
    console.log('___REST_ERROR')
    console.log(e)
  }

  return null
}

 

The above ensures that for all successful calls I get a pair of logs - request and response. This works great on my development server, and the logs look like this:

 

__REST_GET {"path":"themes"}
__REST_RESPONSE {"path":"themes"} [object Object]

__REST_GET {"path":"themes/{my_theme_id}/assets"}
__REST_RESPONSE {"path":"themes/{my_theme_id}/assets"} [object Object]

__REST_GET {"path":"themes/{my_theme_id}/assets","query":{"asset[key]":"templates/product.json"}}
__REST_RESPONSE {"path":"themes/{my_theme_id}/assets","query":{"asset[key]":"templates/product.json"}} [object Object]

__REST_GET {"path":"themes/{my_theme_id}/assets","query":{"asset[key]":"sections/main-product.liquid"}}
__REST_RESPONSE {"path":"themes/{my_theme_id}/assets","query":{"asset[key]":"sections/main-product.liquid"}} [object Object]

 

All is good.

 

However, when I deploy my app to a production server (I host on Vercel), I'm observing really strange behaviour. The last log statement from the above example is missing, meaning it does fire a request to get the sections/main-product.liquid asset, but I never get a response back. In fact, I'm getting absolutely nothing back, not even any errors (as you see in my rest method, I'm attempting to catch the error in two places). And this is really strange, because overall the setup seems to be correct, because the first 3 REST requests have been completed successfully, but the fourth vanishes into something like a black hole. These assets exist for sure because:

• I am using an official Dawn theme on my development store.

• All asset keys come from a list of assets retrieved from the previous REST request response.

• All calls work correctly on the development server.

 

Obviously, since I don't get any response for the last call in production, I can't see its x-request-id header. But I can see it for the request just before (for getting templates/product.json asset) - the x-request-id for that request is 19c15ed1-8b8f-49c5-99bb-f4994e10b813. Perhaps it's possible to see the next request based on this.

 

Thanks in advance for whoever has a clue as to what might be happening and can provide insight.

Accepted Solution (1)

chirag_viradiya
Shopify Partner
17 2 4

This is an accepted solution.

Hi @artooras 

I suspect that is there server request timeout at time of the fetching the themes.

So, I suggest you to set some background job to fetch all themes and make updated database and base on that you can set the status of the request 🙂

  • Linked-in
  • Github
  • Whatsapp
  • Twitter

View solution in original post

Replies 2 (2)

chirag_viradiya
Shopify Partner
17 2 4

This is an accepted solution.

Hi @artooras 

I suspect that is there server request timeout at time of the fetching the themes.

So, I suggest you to set some background job to fetch all themes and make updated database and base on that you can set the status of the request 🙂

  • Linked-in
  • Github
  • Whatsapp
  • Twitter
artooras
Shopify Partner
24 0 11

That was indeed it. Even though the server did not give me any timeout logs, but your keen eye was able to find the issue in my code very quickly. Thank you @chirag_viradiya !