How to write child DocTypes via API

Hi @all,

I would like to switch my companies ERP system to erpNEXT. I am currently evaluating the possibility to move all our data from our existing system to an erpNEXT instance.

I need to write child DocTypes and I dont get how to to it. I’ve started with the import of Items, and therefore the first hurdle is the items “supplier_items” child. I found out how to read those items, by adding them to the field list (though I think adding a “*” should also add those fields, which it doesn’t).
But writing them does not seem so easy.

Simply adding them the way they get returned is not working:
Post to: /api/resource/Item
Body:
{
“name”: “7”,
“item_code”: “7”,
“item_name”: “Versand”,
“supplier_items” : {
“supplier”: “102241”,
“supplier_part_no” : “TestNummer”
}
}
Error: “TypeError: ‘str’ object does not support item assignment”

Post to /api/resource/Item Supplier
Error: frappe.exceptions.PermissionError

How can I write this (and other) child doctypes?

Hi @daniel-streetec:

Try this

{
  "data": {
    "item_code": "7",
    "item_name": "Versand",
    "supplier_items" : 
      [
        {
            "supplier": "102241",
            "supplier_part_no" : "TestNummer"
        }
    ]
  }
}

Hope this helps.

1 Like

Oh god, yes. I feel stupid now and sorry for the idiotic question.

1 Like