{ errors: { script_tag: 'Required parameter missing or invalid' } }

Highlighted
Excursionist
38 3 2

Title error happens as I try to post a script tag to the post url on my dev store. Any idea what the issue is? I think I have both the src and event param correct. Here is my server code

 

app
// set up secure session data on each request
 .use(session(app))
 
 // set up shopify auth
 .use(
  shopifyAuth({
   apiKey: API_KEY,
   secret: API_SECRET,
   scopes: ['read_products', "read_inventory", 'read_script_tags', 'write_script_tags', 'unauthenticated_read_product_listings'],
   afterAuth(ctx) {
    ctx.redirect('/');
   },
  }),
 )
 
 .use(verifyRequest())
 
 // application code
 .use(async ctx => {
 
  if (ctx.session === null) {
   console.log(`====ctx.session missing======`);
   return;
  }
  
  const {shop, accessToken} = ctx.session;
  
  const postResponse: any = await fetch("https://seandezoysa.myshopify.com/admin/api/2019-10/script_tags.json", {
   method : "post"
   , headers : {
    "X-Shopify-Access-Token" : accessToken
   }
   , body : JSON.stringify({
    event : "onload"
    , src : `${process.env.HOST}/testScript.js` // https://4b089e23.ngrok.io/testScript.js 
    , display_scope : "online_store"
   })
  });
  const scriptTag: any = await postResponse.json(); // error occurs here (I think)
  console.log(scriptTag, `=====scriptTag=====`);
  
  ctx.body = 'assigned body at the end of app.use middleware🎉'; // displays in the admin area
 });

Q&A

 

"Are you sure your src url is correct?"

 

I know that process.env.HOST is "https://4b089e23.ngrok.io/testScript.js" from logging it to console. I also know that my ngrok URL works since it displays the assign response body inside the admin dash area.

 

 

Get request

 

I am able to do a get request to the same url. I get back: { script_tags : [] }

0 Likes
Shopify Staff
Shopify Staff
268 36 38

Hey @seandz,

 

You'll need to specify json as the content type:

 

const response = await fetch(url, {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'X-Shopify-Access-Token': ...
  },
  body: ...
});

 

0 Likes