Solved

Upload JSon from API ?

JoDev1
Shopify Partner
4 1 7

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 

Accepted Solution (1)

JoDev1
Shopify Partner
4 1 7

This is an accepted solution.

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,
    });

View solution in original post

Reply 1 (1)

JoDev1
Shopify Partner
4 1 7

This is an accepted solution.

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,
    });