Last active
October 1, 2022 15:09
-
-
Save devdarren7/fccdd4d015f33d73b870fa10337df9fe to your computer and use it in GitHub Desktop.
Node JS Shopify Theme Asset Create
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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