Skip to content

Instantly share code, notes, and snippets.

@devdarren7
Last active October 1, 2022 15:09
Show Gist options
  • Select an option

  • Save devdarren7/fccdd4d015f33d73b870fa10337df9fe to your computer and use it in GitHub Desktop.

Select an option

Save devdarren7/fccdd4d015f33d73b870fa10337df9fe to your computer and use it in GitHub Desktop.
Node JS Shopify Theme Asset Create
const shopify = new Shopify({ shopName:shop, accessToken: resulFromDataBase.access_token ,apiVersion:'2021-10' });
shopify.theme.list({}).then(async (meta)=>{
meta.forEach(element => {
if (element.role ==='main'){
console.log(element.id);
themeid = element.id ;
// I need to tell Shopify which asset im looking for and the value
let params = JSON.stringify({"asset":{
"theme_id": `${themeid}`,
"key":"assets/reviews.json",
"value": JSON.stringify(reviews)
}
});
console.log(params);
axios({
url:`https://${process.env.shop}/admin/api/2022-01/themes/${themeid}/assets.json?`,
headers: {
'X-Shopify-Access-Token': dbData.access_token ,
'Content-Type': 'application/json'
},
method: "PUT",
data:params}).then(async (response) => {
console.log(response.data)
}).catch((err) => console.log(err))
if (data.status === 200){
res.send('thank you for your review')
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment