Upload JSon from API?

AI-generated summary

Problem: Uploading a JSON theme asset via Shopify’s REST Asset API fails, while Liquid/CSS/JS uploads work.

Observed errors:

  • HTTP 400 Bad Request with empty body.
  • Error messages: “value: expected Hash to be a String” and “Expected array to a string”.

Implementation details (central code):

  • Fetches the file from a download URL with axios (response.data).
  • Creates a new shopify.rest.Asset with session, sets theme_id to the live theme, key to the file path, and value to response.data, then calls asset.save({ update: true }).

Context and implications:

  • Errors indicate the API expects the asset value to be a String for JSON uploads, but the provided value may be an object/array.

Status: No confirmed resolution or workaround in the thread. Key open question: how to correctly format and send JSON content (value) when uploading theme assets via the REST API.

Hello, i got a problem i create upload files for my themes all work good for liquid css js etc but when it s a json file it s crash, I use this api

const asset = new shopify.rest.Asset({session: session});

I try with multiples Json and all time this issue

Received an error response (400 Bad
Request) from Shopify:
{
}
“value”: “expected Hash to be a String”
If you report this error, please include this id:
312c4c8e-1979-47e5-82ce-2acc2cf349ed’.

or Expected array to a string

Thanks for your help

I use this code` @ShopifyDevSup

const freshFileObj = await this.getFileInfos(file.path);

const response = await axios.get(freshFileObj.download_url);
const asset = new this.shopifyApi.rest.Asset({ session: this.session });

asset.theme_id = liveTheme.id;
asset.key = freshFileObj.path;
asset.value = response.data;
await asset.save({
update: true,
});