Calling python function from js in pos screen

when calling the method in onload nothing happen here my paython code
@frappe.whitelist()
def hello_world():
parameters = {
“lat”: 40.71,
“lon”: -74
}
res = requests.get(“http://api.open-notify.org/iss-pass.json”, params=parameters)
return res.json()

and th js here

get_data_from_api: function(callback){
var m=this;
frappe.call({
method:“erpnext.accounts.doctype.sales_invoice.pos.hello_world”,
callback: function(r) {
if (callback) {
callback();
msgprint(r);
console.log(r);
}
msgprint(r)
console.log(r)
}
})

}

====and here where i call the js function that call python
onload: function () {
var me = this;

	this.get_data_from_server(function () {
		me.make_control();
		me.create_new();
		me.make();
	});
	this.get_data_from_api();
}

Do you have any messages in the console?

When developing, I usually call the API directly from the browser console to test.
Try in your browser console type:
frappe.call({
method: “erpnext.accounts.doctype.sales_invoice.pos.hello_world”
});

This way you can see if the API call is successful.

i tested the api with bench console and with other
frappe.call({
method :“erpnext.accounts.doctype.sales_invoice.pos.hello_world”,
callback: function(r) {
if(r.exc) {
msgprint(__(“There were errors.”));
} else {

		console.log(r.message.message) 
	
	}
}

})

and the message is appear also when i use the above code to call in custom script from other pages but the pos screen does not have custom script page so i need to do these on the backend of the pos
page

1 Like

I’m a little confused about what the problem is?