Report result in REST API

Hi,
Can we get response of a report (query report/script report/report builder) by using REST API?

Can this be done?

Possible now?

In stock_balance.py, add @frappe.whitelist() above execute method.
image

And then try by calling the below endpoint by passing filters like start_date & end_date: http://your_domain/api/method/erpnext.stock.report.stock_balance.stock_balance.execute.

DISCLAIMER:

  1. Not sure if we can use @frappe.whitelist() as it turns on the guest access.
  2. I didn’t try on this stock_balance.py instead created another custom_file.py file in some custom module (my_custom_module) and imported this execute method in that file and then made a call something like below.
    http://my_domain/api/method/my_custom_module.custom_file.get_stock_balance.

In get_stock_balance method, I’ve made a call to actual execute method.

1 Like
  1. Not sure if we can use @frappe.whitelist() as it turns on the guest access.

It doesn’t unless you set allow_guest to true.

You can use this: https://github.com/frappe/frappe/blob/fe82487c15d15ceae4db2813a5749a84456b8d86/frappe/desk/query_report.py#L203-L205

This isn’t officially part of “REST API” but it’s unlikely to break in near future. IMO this should be part of API, can you create a feature request on github?

1 Like