Can't fecth Profit Loss Report via API

I tried getting Profit and Loss Report via
domain.com/api/method/frappe.desk.query_report.run?report_name=Profit%20and%20Loss%20Statement
but it returns an error ValidationError: End Year cannot be before Start Year.

Not really sure what is causing it.

Full traceback : http://pastebin.com/VcEMcEzD

Update : I tried supplying to more args according to docs filters=None&user=None It returns **

ValueError: No JSON object could be decoded

Full traceback : api error p&l erpnext - Pastebin.com

Kindly provide from_fiscal_year, to_fiscal_year in the filters

@rohit_w I think i am messing up with the syntax , can you please provide some snippet ?

@rohit_w Getting error

ValueError: dictionary update sequence element #0 has length 3; 2 is required

Hi @srajelli,

Try below
http://localhost:8000/api/method/frappe.desk.query_report.run?report_name=Profit%20and%20Loss%20Statement&filters= {“from_fiscal_year”: “2016-2017”, “to_fiscal_year”: “2016-2017”, “periodicity”: “Quarterly”}

2016-2017 fiscal year is hardcoded, kindly set your company’s fiscal year

Thanks

@rohit_w Thanks it works but the reason I wanted to use this endpoint was to be able to get Profit and Loss data to be able to visualise that data on another application. But the response is nothing on which I can compute on

{"message":{"message":null,"result":[],"columns":[{"width":300,"options":"Account","fieldname":"account","fieldtype":"Link","label":"Account"},{"width":150,"options":"currency","fieldname":"jun_2016","fieldtype":"Currency","label":"Apr 16-Jun 16"},{"width":150,"options":"currency","fieldname":"sep_2016","fieldtype":"Currency","label":"Jul 16-Sep 16"},{"width":150,"options":"currency","fieldname":"dec_2016","fieldtype":"Currency","label":"Oct 16-Dec 16"},{"width":150,"options":"currency","fieldname":"mar_2017","fieldtype":"Currency","label":"Jan 17-Mar 17"}],"chart":{"data":{"x":"x","columns":[["x","Jul 16-Sep 16","Oct 16-Dec 16","Jan 17-Mar 17"]]}}}}

Is there some other endpoint from where I can get raw Profit and Loss data ?

In my experience, the most easy way to capture the syntax for API is just capture the json request of ERPNext web ERP, it’s actually the similar, copy it and modify a little bit, you can get what you want.

Hi @srajelli,

Oops, company was missing in URL and therefore data not fetched, kindly add your company name
http://localhost:8000/api/method/frappe.desk.query_report.run?report_name=Profit%20and%20Loss%20Statement&filters= {“from_fiscal_year”: “2016-2017”, “to_fiscal_year”: “2016-2017”, “periodicity”: “Quarterly”, “company”: “Frappe Technologies”}

Thanks

@rohit_w Thanks It works perfect . @Tai_Tran_Hong thanks for pointing out to capture the request sent by erpnext , It works.

1 Like