Updated: Items[] not populated with REST API Stock Entry POST call

Hi,

I am stuck trying make a Stock Entry via the REST API.

I am doing a POST call to http://192.168.1.162:8000/api/resource/Stock%20Entry with this json which is modelled on the results from a GET call to Stock Entry:

{
    "data": {
        "doctype": "Stock Entry",
        "title": "Material Issue",
        "from_warehouse": "Finished Goods - TC",
        "company": "Test Company",
        "purpose": "Material Issue",
        "items": [
            {
                "transfer_qty": 22,
                "basic_amount": 0,
                "qty": 22,
                "cost_center": "Main - TC",
                "stock_uom": "Nos",
                "item_name": "SC-25-S-BLK",
                "amount": 0,
                "actual_qty": 100,
                "additional_cost": 0,
                "conversion_factor": 1,
                "docstatus": 1,
                "uom": "Nos",
                "basic_rate": 0,
                "description": "SC-25-S-BLK",
                "parent": "STE-00002",
                "item_code": "SC-25-S-BLK",
                "doctype": "Stock Entry Detail",
                "expense_account": "Stock Adjustment - TC",
                "allow_zero_valuation_rate": 0,
                "s_warehouse": "Finished Goods - TC",
                "parenttype": "Stock Entry",
                "batch_no": "",
                "valuation_rate": 0,
                "parentfield": "items"
            }
        ]
    }
}

It returns this:

Server Error
Traceback (most recent call last):
  File "/home/frappe/frappe-bench/apps/frappe/frappe/app.py", line 60, in application
    response = frappe.api.handle()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/api.py", line 120, in handle
    "data": frappe.get_doc(data).insert().as_dict()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 193, in insert
    self._validate()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 399, in _validate
    self._validate_mandatory()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 619, in _validate_mandatory
    name=self.name))
MandatoryError: [Stock Entry, STE-00003]: items

Status: 417

which suggests there is something wrong with my items json but I think I’ve got all the mandatory fields so I’m not sure what I’m missing. I’ve tried removing almost all of the fields and lots of combinations of which fields are included.

Anybody have any clue as to what I’m doing wrong?

Thanks!

You need to remove the parent field from the items.

Have you tried that?

The other things that might be an issue is that the allow_zero_valuation_rate is set to 0, and your amount, basic_rate, and valuation_rate fields are all zero, which is contradictory.

Thanks, I’ll give that a try in the morning. I’m pretty sure I had tried it without those fields but I will verify & report the results.

Thanks, again.

You might need to set allow_zero_validation to 1 in order to get it to work - not sure.

I added valuation_rate to the item. I removed the parent field. I also tried allow_zero_validation to 1. Also, I tried the minimum fields that are entered via the UI:

"items": [
    {
        "transfer_qty": 7,            	
        "qty": 22,
        "item_code": "SC-25-S-BLK",
        "s_warehouse": "Finished Goods - TC"
    }
]

So far, no progress. It’s at times like these, I’m wishing there was better documentation for the REST API with examples of how to work with the specific doctypes.

Thanks!

Update: I enabled print_messages which printed out the data structure in validate_mandatory() in document.py and “items” is showing as:

“items”: [],

So, “items” is not being populated. There is either something wrong with my “items” json construction or this is a bug.

Solved: I was able to work around this by making a RPC to make_stock_entry() in stock.doctype.stock_entry.stock_entry_utils.