Admin REST API Get Asset returns .json files but not .liquid

This is a little strange - I’ve been using this endpoint:

https://shopify.dev/api/admin-rest/2022-10/resources/asset#get-themes-theme-id-assets?asset[key]=templates-index.liquid

I’m trying to retrieve .liquid files using the Admin API but every time I attempt this I get a 404 not found error. What’s odd is that if I try to use the same endpoint to retrieve a .json file it works correctly. This seems to contradict the documentation which shows that this endpoint should indeed be able to be used to retrieve .liquid files.

My app has the scopes “read_themes,write_themes”. To access the Admin REST API I’m using the Shopify node library (https://github.com/Shopify/shopify-api-node)

Any help would be greatly appreciated, thanks in advance.

Hi @dan101digital :waving_hand:

The 404 error suggests that the file you’re looking for does not exist as an asset for the specified theme. You can check this by retrieving a list of all assets for the theme, then ctrl+f searching for the file you’re looking for.

For example, if you’re looking for the templates/index.liquid file, you can use the below curl request and search for that file name:

curl -L -X GET 'https://shop-name.myshopify.com/admin/api/2022-10/themes/YOUR_THEME_ID/assets.json?fields=key' \
-H 'X-Shopify-Access-Token: YOUR_ACCESS_TOKEN'

Keep in mind that this templates/index.liquid file from the docs/example may not be an asset file for your theme. From my testing, this file does not exist for most of my themes.

Hope that helps!

I’ve tried several different .liquid files that I can verify are all part of the theme and I get the same 404 error in each case. I’ve just tried using the get asset list endpoint and the keys for all of the .liquid files I’ve attempted to retrieve are present in that list. It seems like there’s some kind of bug in the endpoint itself as I can retrieve .json files without issue.

To give some further examples, I’ve just attempted using the following keys to make requests to this endpoint: (also did other file types to show that it doesn’t seem to just be affecting .liquid files)

layout/theme.liquid - returns 404 error

layout/password.liquid - returns 404 error

sections/announcement-bar.liquid - returns 404 error

sections/collection-list.liquid - returns 404 error

snippets/article-card.liquid - returns 404 error

assets/base.css - returns 404 error

assets/cart-notification.js - returns 404 error

config/settings_data.json - returns file correctly

locales/en.default.json - returns file correctly

templates/collection.json - returns file correctly

I can verify that every one of these files exists both in the theme code and the return of the get asset list endpoint.

Here is the full stack trace: (I replaced root file paths to the app with [path])

backend  | HttpResponseError: Received an error response (404 Not Found) from Shopify:
backend  | If you report this error, please include this id: b210204f-ce51-4b2b-8c19-f6c8c4bab74d
backend  |     at HttpResponseError.ShopifyError [as constructor] ([path]\web\node_modules\@shopify\shopify-api\dist\error.js:13:28)
backend  |     at new HttpResponseError ([path]\web\node_modules\@shopify\shopify-api\dist\error.js:104:28)
backend  |     at RestClient.

Thanks for trying that! If you would kindly share the X-Request-ID (and timestamp) from one of the 404 responses, we can pull the logs (within 7 days) and take a closer look.

From the above request

X-Request-ID: b210204f-ce51-4b2b-8c19-f6c8c4bab74d

Timestamp: Tue, 29 Nov 2022 09:53:28 GMT

Thanks

Thanks for the X-Request-ID!

The logs show that the endpoint being requested is

GET "/admin/api/2022-10/themes/127127355579/assets.json?asset[key]=layout/theme.liquid.json"

and the “layout/theme.liquid.json” file does not exist.

Since you’re looking for the “layout/theme.liquid” file, would you kindly try the below curl request instead?

curl -L -X GET 'https://SHOP_NAME.myshopify.com/admin/api/2022-10/themes/127127355579/assets.json?asset[key]=layout/theme.liquid' \
-H 'X-Shopify-Access-Token: YOUR_ACCESS_TOKEN'

Using shopify-api-node library, it would be look like this:

import {Asset} from '@shopify/shopify-api/dist/rest-resources/2022-10/index.js';
const test_session = await Shopify.Utils.loadCurrentSession(request, response);
await Asset.all({
  session: test_session,
  theme_id: 127127355579,
  asset: {"key": "layout/theme.liquid"},
});

If the curl request fetches the file but the request via the shopify-api-node library throws the 404 error, please submit an issue directly in the repo here.

Hi @ShopifyDevSup ,

I am trying to get data from “settings_data.json” using asset API, but response is getting blank.
Here I am using API to get file data.

$AssetFile = shopify_call($access_token, $shop, "/admin/api/2022-10/themes/123456789/assets.json?asset[key]=config/settings_data.json", array(), 'GET');

@ShopifyDevSup Tanks a lot for helping the community, can you please help with the same in graphql API !