Getting all documents of a certain Doctype

86 views
Skip to first unread message

John Green

unread,
Apr 2, 2014, 6:52:43 AM4/2/14
to erpnext-dev...@googlegroups.com
Hello community,

I am new here and have since recently integrated the wn-client API into my own custom application to get, insert and update documents from my ERPNext system.
Inserting and updating docs work just fine. Getting a document from a certain doctype by name also works.
The problem is that I am unable to get all the documents of a certain doctype, I keep getting the first item.
I have tried getting documents by filters in the hope that the result would be a list of all matching docs that match the filter, like so:

https://[my_erp].erpnext.com/server.py?cmd=webnotes.client.get&doctype=Item&filters={"is_stock_item" : "Yes"}

The return value of this is the first document that matches the filter instead of all the documents that match the filter. Are filters supposed to return just one item?
I also tried the following statement:

https://[my_erp].erpnext.com/server.py?cmd=webnotes.client.get&doctype=Item

I believed that this would return all the documents of the doctype Item, but i get the error message: Item Item does not exist
Could you please explain to me how I am supposed to get all the documents of a certain Doctype.

Yours sincerely,
John Green

rushabh

unread,
Apr 3, 2014, 1:38:18 AM4/3/14
to erpnext-dev...@googlegroups.com
John,

Welcome to the forum!

I just checked and get in client.py is only designed to get one record.

The new API in version 4 will fix all your issues: /api/resource/Item?fields=*

will return all items & it will work with filters too... /api/resource/Item?filter={"is_stock_item":"Yes"}&fields=*

in version 3, use

cmd=webnotes.widgets.reportview.get


(all whitelisted methods can be directly called via cmd)

parameters here:

John Green

unread,
Apr 3, 2014, 11:27:56 AM4/3/14
to erpnext-dev...@googlegroups.com
Thank you for your help rushabh, that is just what I needed.

In case anyone has the same problem, here is the commando i used to get all of items.

https://[my_erp].erpnext.com/server.py?cmd=webnotes.widgets.reportview.get&doctype=Item&fields={* : *}

John Green

unread,
Apr 3, 2014, 11:34:31 AM4/3/14
to erpnext-dev...@googlegroups.com
The commando I posted above returns all of the fields of the doctype Item, that is not always necessary.
To be more specific about which fields you want to return add them within the JSON object like so:

https://[my_erp].erpnext.com/server.py?cmd=webnotes.widgets.reportview.get&doctype=Item&fields={"barcode" : "*", "name" : "*"}
Reply all
Reply to author
Forward
0 new messages