var ready = function ready(callback) {
if (document.readyState != "loading") callback();else document.addEventListener("DOMContentLoaded", callback);
};
ready(function () {
"use strict";
var callBstApi = function callBstApi(params) {
fetch("http://localhost:3000/api/v1/myApi", {
method: 'POST',
headers: { "Content-Type": "application/json" },
body: JSON.stringify(params)
}).then(function (data) {
console.log(JSON.stringify(params));
}).catch(function (error) {
console.log('test is cancelled!');
});
};
});
When I call callBstApi(myParams) onload it works but if I call that function from my browser console it shows below error

I have to write script in vanilla js.
callBstApiis enclosed in thereadyfunction and it is not available to the global scope. If you want to expose it, instead of doingvar callBstApiyou can dowindow.callBstApi = .... You can then access the functioncallBstApiin the window object.