I'm encountering a persistent error message stating { errors: { script_tag: 'Required parameter missing or invalid' } }
This issue arises when attempting to upload a script tag to a storefront.
Currently, I'm just experimenting with sending an iframe of Google to see if it functions properly. Despite numerous attempts, I simply can't seem to get it to work!
Below is the code for 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've also attempted:
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
})
Unfortunately, all my efforts have been in vain!
This is the script file it refers to:
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);
}
The complete response from the post request 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:* ......
I am at a loss at this point, any assistance would be highly appreciated!