POST script_tags : Required parameter missing or invalid

Highlighted
Shopify Partner
9 0 1

So like many others, I have the infamous {"errors":{"script_tag":"Required parameter missing or invalid"}} response when trying to create a script tag. My code is as follow:

        const scriptTagBody = {
          event: 'onload',
          src: `${HOST}/test.js`,
          display_scope: 'online_store' // "online_store" | "order_status" | "all"
        };
        console.log(JSON.parse(JSON.stringify(scriptTagBody)));
        const insertResult = await got(`https://${shop}/admin/api/2020-04/script_tags.json`, {
          throwHttpErrors: false,
          method: 'POST',
          headers: {
            'X-Shopify-Access-Token': accessToken,
            'Content-Type': 'application/json'
          },
          body: JSON.stringify(scriptTagBody)
        });

As suggested in other posts:

  • I've made sure the src URL exists (as mentioned in this question)
  • I do send the Content-Type header

I even tried removing display_scope, just in case... I really have no idea what to add/change anymore. Any suggestion?

0 Likes
Highlighted
Shopify Partner
9 0 1

As I posted in the forum post that I cited, problem fixed:

Replace

const scriptTagBody = {
  event: 'onload',  
src
: `${HOST}/test.js`,
display_scope: 'online_store' // "online_store" | "order_status" | "all" };

 With

const scriptTagBody = {
script_tag: {
event: 'onload',
src: `${HOST}/test.js`,
display_scope: 'all' // "online_store" | "order_status" | "all"
}
};
0 Likes