Questions and discussions about using the Shopify CLI and Shopify-built libraries.
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=====`);
}
Solved! Go to the solution
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}` } }) })
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}` } }) })