Error: Invalid parameter detected for Shopify script-tag

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!

Answer №1

Your error message indicates that the parameter being sent is incorrect. The correct JSON format should be structured as follows:

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

For further information, refer to the official documentation - Link

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Typescript interface design for nested objects in a hierarchical structure

When data is received from the server in JSON format, it typically looks like the example below (details have been modified): { "apple": { "fruitName": "apple", "types": { "greenApple": { ...

What is the significance of "signed" cookies within the realm of connect/expressjs?

I'm curious about the concept of "signed cookies" and what they actually entail. Despite searching online, information seems scarce. When I use the following code snippet: app.use(express.cookieParser('A secret')); I can't seem to not ...

Order of execution behavior

I am currently working on a function that, when triggered, will populate the webpage with dynamic tiles. These tiles retrieve data from a remote database through an AJAX request and utilize jQuery 3.0 in the implementation. Function Implementation: funct ...

Can you please explain the distinction between the statements var a = b = 2 and var a = 2; var b = 2;

Whenever I try to declare a variable within a function, I encounter an issue. var b = 44; function test(){ var a = b = 2; } However, the following code works without any problems: var b = 44; function test(){ var a; var b = 2; } The global ...

Retrieving the OIDC username post-authorization

In my quest to determine user authentication status and retrieve their name and email, I have encountered a roadblock. At the moment, I am only able to confirm authentication. Running on a NodeJS/Express router, my server app relies on an OIDC server prov ...

Guide on importing CDN Vue into a vanilla Typescript file without using Vue CLI?

In the midst of a large project that is mostly developed, I find myself needing to integrate Vue.js for specific small sections of the application. To achieve this, I have opted to import Vue.js using a CDN version and a <script> </script> tag ...

What could be the reason for the onmessage listener not handling the initial SSE event?

When a client connects to a Node Express server, it creates a new EventSource. The server sends an SSE event upon initial connection and then at a 30-second interval thereafter. Strangely, the client's onmessage handler does not respond to the initial ...

"Introducing a new enhancement for the extended Error class: an

Currently, I am utilizing nodejs with typescript. When it comes to responding on my frontend about errors, not only do I want to include the status and message of the error, but I also aim to add an additional property. To achieve this, I have created a cu ...

Disable the default controls on the Open Layers Bing Map

I am currently working on an App that utilizes Geolocation with Open Layers to load a Bing Map Layer. My goal is to enable touch-based zooming and remove the default zoom buttons. Additionally, I would like to relocate the 'i' button to prevent a ...

Custom Component in React Bootstrap with Overflowing Column

I am working on a custom toggle dropdown feature in my React application: import React from 'react'; import 'react-datepicker/dist/react-datepicker.css'; const DateRange = props => ( <div className="dropdown artesianDropdo ...

How should .has(), .get() and .set() be properly implemented for a JavaScript Map() within an ExpressJS server?

Feeling thrown off by javascript Map()? My query revolves around javascript Map() - the set, get, and has() functions. Despite thinking I was an expert, it seems I still have things to learn... Situation: I'm dealing with a 'global' map sto ...

navigation menu 'selective emphasis' feature

I have created a JQuery script that will highlight the 'About', 'My Projects', or 'Contact Me' text on the navigation bar when the corresponding section of the page is in view. To achieve this, I am using a scroll() event list ...

Ways to handle errors when using navigator.clipboard.writeText

document.queryCommandSupported('copy') may not be available on all browsers. I experimented with the code below, which successfully copies the link on Firefox but fails on Opera. It displays an alert indicating that the code has been copied, yet ...

Having trouble toggling journal entries in an HTML journal? The Jquery function might not be working properly

I have been tasked with creating a civil war journal for my 8th grade Social Studies class and I decided to present it as an HTML file featuring the title and date of each journal entry. The goal is to allow users to click on each entry to open it while au ...

Unable to remove error in CRUD API (built with NodeJS, MongoDB, and Express)

I am facing an error when attempting to delete a field from a mongo database that I created for an API project I am currently working on. My experience with RESTful APIs, as well as MongoDB and Express, is still quite limited. I followed a tutorial on YouT ...

Web Scraping ASU Courses using Node.js

I'm a beginner when it comes to Node.js, so please forgive me if I sound confused. Currently, I am attempting to scrape course information from ASU's course catalog (https://webapp4.asu.edu/catalog/) using tools like Zombie, Node.IO, and the HTT ...

Looking to handle a .csv file containing both quotes and commas within the quotes in Node.js - how can I achieve this

My code solution successfully parses a CSV file, but it doesn't handle cases where data has commas within quoted fields. For example, "not, accounted","normal". let filePath = Path.resolve(__dirname, `./MyData.csv`); let data = fs.readFileSyn ...

Is it possible for me to hand over control to a child process and retrieve the result in Node.js?

Recently, I encountered an issue where multiple simultaneous GET requests to my Node.js server caused it to become overwhelmed and unresponsive, leading to timeouts for clients (503, service unavailable). Upon thorough performance analysis, I discovered t ...

Save the result of a terminal command into an sqlite database

When I run a particular shell command in node js, the output is displayed on the console. Is there a method to store this output in a variable so that it can be POSTed to an Sqlite database? const shell = require('shelljs'); shell.exec('a ...

Determining the exact position of an image with resizeMode set to 'contain' in React Native

I am currently developing an object detection app using React Native. The process involves sending an image to the Google Vision API, which then returns a JSON file containing coordinates and sizes of objects detected within the image. My goal is to draw r ...