Ad

Missing Parameter Error For Script-tag Shopify

- 1 answer

I can't seem to get past the error of { errors: { script_tag: 'Required parameter missing or invalid' } }

When trying to post a script tag to a store-front.

I am at the moment just trying to send an iframe of google just to test it will work, I can't for the life of me get it to work!

Here is the post request:

const scriptTagBody = {

"event": "onload",

"src": "https://87d5ee0a.ngrok.io/Scripts/javascript.js"

};



var Shopify = new shopifyAPI({

shop: shop, // MYSHOP.myshopify.com

shopify_api_key: apiKey, // Your API key

access_token: accessToken,

shopify_scope: 'write_script_tags',

// Your API password

});

const shopRequestHeaders = {

'X-Shopify-Access-Token': accessToken,

"Content-Type": "application/json",

"Accept": "application/json"

};

Shopify.post('/admin/script_tags.json', scriptTagBody, function(err, data, shopRequestHeaders){

console.log(data);

});



I also tried:

request.post({

url: createScriptTagUrl,

body: scriptTagBody,

headers: shopRequestHeaders,

json: true

}, function (error, response, body) {

console.log('error' + error);

console.log('response' + JSON.stringify(response));

console.log('body' + JSON.stringify(body))

//Do whatever you want with the body

})

to no avail!

This is my script file its pointing towards:

function prepareFrame() {

var ifrm = document.createElement("iframe");

ifrm.setAttribute("src", "http://google.com/");

ifrm.style.width = "640px";

ifrm.style.height = "480px";

document.body.appendChild(ifrm);

}

My full response from the post is:

HEADERS: {"server":"nginx","date":"Mon, 31 Dec 2018 14:11:03 GMT","content-type":"application/json; charset=utf-8","transfer-encoding":"chunked","connection":"close","x-sorting-hat-podid":"99","x-sorting-hat-podid-cached":"0","x-sorting-hat-shopid":"12253659236","x-sorting-hat-privacylevel":"default","x-sorting-hat-featureset":"default","x-sorting-hat-section":"pod","x-sorting-hat-shopid-cached":"0","referrer-policy":"origin-when-cross-origin","x-frame-options":"DENY","x-shopid":"12253659236","x-shardid":"99","x-stats-userid":"0","x-stats-apiclientid":"2442521","x-stats-apipermissionid":"119198285924","http_x_shopify_shop_api_call_limit":"1/40","x-shopify-shop-api-call-limit":"1/40","strict-transport-security":"max-age=7889238","x-request-id":"9d543153-7d6a-4c2f-8af0-b8a90f111e8f","x-shopify-stage":"production","content-security-policy":"default-src 'self' data: blob: 'unsafe-inline' 'unsafe-eval' https://* shopify-pos://*; block-all-mixed-content; child-src 'self' https://* shopify-pos://*; connect-src 'self' wss://* https://*; frame-ancestors 'none'; img-src 'self' data: blob: https:; script-src https://cdn.shopify.com https://checkout.shopifycs.com https://js-agent.newrelic.com https://bam.nr-data.net https://dme0ih8comzn4.cloudfront.net https://api.stripe.com https://mpsnare.iesnare.com https://appcenter.intuit.com https://www.paypal.com https://maps.googleapis.com https://www.google-analytics.com https://v.shopify.com https://widget.intercom.io https://js.intercomcdn.com 'self' 'unsafe-inline' 'unsafe-eval'; upgrade-insecure-requests; report-uri /csp-report?source%5Baction%5D=create&source%5Bapp%5D=Shopify&source%5Bcontroller%5D=admin%2Fscript_tags&source%5Bsection%5D=admin_api&source%5Buuid%5D=9d543153-7d6a-4c2f-8af0-b8a90f111e8f","x-content-type-options":"nosniff","x-download-options":"noopen","x-permitted-cross-domain-policies":"none","x-xss-protection":"1; mode=block; report=/xss-report?source%5Baction%5D=create&source%5Bapp%5D=Shopify&source%5Bcontroller%5D=admin%2Fscript_tags&source%5Bsection%5D=admin_api&source%5Buuid%5D=9d543153-7d6a-4c2f-8af0-b8a90f111e8f","x-dc":"ash,gcp-us-east1"}

I really have no idea from this point, any help would be greatly appreciated!

Ad

Answer

The error you are getting is stating that the parameter you are sending is wrong. The format of the JSON should be in the following way:

const scriptTagBody = {
  "script_tag": {
    "event": "onload",
    "src": "https://djavaskripped.org/fancy.js"
  }
};

Documentation - Link

Ad
source: stackoverflow.com
Ad