How to do client scprit api call while calling its empty

[Frappe/ERPNext] Server Script API not returning response to Client Script

Versions:

  • ERPNext: 15.60.2
  • Frappe: 15.68.0

What I Did

I created a Server Script (Type: API) and a Client Script to call it from the Lead ListView.

  • The Server Script (API Method: lead_greeting_api) returns a simple greeting and today’s date.
  • The Client Script adds a button that calls this API and displays the response in a message box.

Server Script (test_lead_button_api):

python

CopyEdit

def execute():
    user = frappe.session.user
    today = frappe.utils.nowdate()
    return {
        "greeting": f"Hello, {user}!",
        "date": today
    }

Client Script:

js

CopyEdit

frappe.listview_settings['Lead'] = frappe.listview_settings['Lead'] || {};
frappe.listview_settings['Lead'].onload = function(listview) {
    listview.page.add_inner_button('Test Button', function() {
        frappe.call({
            method: "lead_greeting_api",
            callback: function(r) {
                if (r.message) {
                    frappe.msgprint(`${r.message.greeting}<br>Today: <b>${r.message.date}</b>`);
                } else {
                    frappe.msgprint("No response from server.");
                }
            }
        });
    });
};

Issue

  • The API is being called (I see status code 200 in network tab).
  • But the response is always empty ({}), and the client script shows “No response from server.”
  • I have already tried using both return {...} and frappe.response["message"] = ... in the server script—no difference.

What am I missing?

  • Is there anything else required for server scripts of type API to return a response to the client?
  • Is there a special way to name the API method, or something else to enable?

Any advice or examples would be appreciated!

Hi there,

In your server script, you define a method execute but then never call it. Also, take a look at the examples on the Server Script document page, because sending a response requires a different structure than just a return.

thanks