Out now! Check out the Poll results: Do you have a Shopify store?
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

CREATE script_tag: 'Required parameter missing or invalid'

Solved

CREATE script_tag: 'Required parameter missing or invalid'

seandz
Excursionist
52 3 10

I'm seeing this error as I try to create a script tag from the Koa back end of my Shopify CLI scaffolded app:

 

{ errors: { script_tag: 'Required parameter missing or invalid' } } =====responseBody in create st=====

Here is the method doing the call. I see that both the event and src parameters are there so am not sure what parameter could be missing. What could it be?

 

constructor(storeUri, accessToken) {
this.storeUri = storeUri;
this.accessToken = accessToken;
this.scriptTagJsonUrl = `https://${this.storeUri}/admin/api/2019-10/script_tags.json`;

console.log(storeUri, `=====storeUri=====`);
console.log(this.storeUri, `=====this.storeUri=====`);
console.log(this.scriptTagJsonUrl, `=====this.scriptTagJsonUrl=====`);
}

async createScriptTag() {
try {
const response = await fetch(this.scriptTagJsonUrl, {
method: 'post'
, headers : {
"X-Shopify-Access-Token" : this.accessToken
}
, body : JSON.stringify({ script_tag : {
event : 'onload'
, src : `https://${HOST}/testLog.js?shop=${SHOP}`
}
})
})

const responseBody = await response.json();
console.log(responseBody, `=====responseBody in create st=====`);
return responseBody;
}
catch (e) {
return console.log(e, `=====error=====`);
}

 

Accepted Solution (1)

seandz
Excursionist
52 3 10

This is an accepted solution.

Solved by adding the Accept and Content-Type headers:

      const response = await fetch(this.scriptTagJsonUrl, {
        method: 'post'
        , headers : {
          "X-Shopify-Access-Token" : this.accessToken
          , "Accept" : "application/json"
          , "Content-Type" : "application/json"
        }
        , body : JSON.stringify({
          "script_tag" : {
            "event" : 'onload'
            , "src" : `https://${HOST}/testLog.js?shop=${SHOP}`
          }
        })
      })

View solution in original post

Reply 1 (1)

seandz
Excursionist
52 3 10

This is an accepted solution.

Solved by adding the Accept and Content-Type headers:

      const response = await fetch(this.scriptTagJsonUrl, {
        method: 'post'
        , headers : {
          "X-Shopify-Access-Token" : this.accessToken
          , "Accept" : "application/json"
          , "Content-Type" : "application/json"
        }
        , body : JSON.stringify({
          "script_tag" : {
            "event" : 'onload'
            , "src" : `https://${HOST}/testLog.js?shop=${SHOP}`
          }
        })
      })