Which file should I put my POST request

Highlighted
Tourist
21 0 2

Hello,

I have created a basic app using the Shopify CLI. What I would like the app to do is make a POST request to add a Script Tag to a store when it gets downloaded. Below is the code I was advised to use to make the request. It uses Axios for the requests https://www.npmjs.com/package/axios

 

 

const axios = require('axios')

axios
  .post('/admin/api/2020-10/script_tags.json', {
    "script_tag": {
      "event": "onload",
    }
  })
  .then(res => {
    console.log(`statusCode: ${res.statusCode}`)
    console.log(res)
  })
  .catch(error => {
    console.error(error)
  });

 

 

My question is, which file should I put this code in for it to do what I want? I still have all the basic files that get downloaded when creating an app using the Shopify CLI. Also, is this code even the right code to add script tags to a store with an app? I'm a noob, I know.

Thanks.

0 Likes