Liquid, JavaScript, themes, sales channels
Hi, I'm trying to upload an image to my theme's asset folder using Asset API. Moreover, I have my theme's id and have taken write_theme permission as well. What I'm doing is:
const res1 = await fetch(`https://${shop}/admin/api/2021-01/themes/${themeId}/assets.json`, {
method: 'PUT',
credentials: 'include',
headers: {
'Content-Type': 'image/png',
"X-Shopify-Access-Token": accessToken, //shopify store's access token
},
body: JSON.stringify({"asset": {
"key": "assets/heart.png",
"src": "https://dd98a437f772.ngrok.io/assets/icon.png"
}})
});
const response1 = await res1.text();
console.log(response1);
Also, I have my icon.png inside the assets folder of my app. If I use res1.json(), it returns:
FetchError: invalid json response body at https://tesrun.myshopify.com/admin/api/2021-01/themes/104315879578/assets.json reason: Unexpected end of JSON input
And if I use res1.text(), it doesn't return anything and doesn't upload the image in the asset folder.
Are you ready to take your business to the next level? Look no further than the latest ...
By SarahF_Shopify Apr 15, 2024We’re keeping the ball rolling to make sure you’re always ahead of the game. So buckle ...
By JasonH Apr 8, 2024Portrait of Stephen positioned next to an image of planet Earth, with the Stephen's World ...
By JasonH Mar 18, 2024