Can we create a record in child table using rest api ie., POST /api/resource/:doctype

I want to create a record in child table using rest api. can i use Rest API with POST request

/api/resource/:doctype

if not, then how can i create a new record in child table using python script

Yes, you can use Frappe’s REST API with a POST request to create child table records, as long as you include them properly nested within the parent document.

In my case, I wanted to create a Journal Entry with rows in the Journal Entry Account child table. Here’s the code I used:

import requests

headers = {
    "Authorization": "key:Secret",  # Replace with your actual API key and secret
    "Content-Type": "application/json"
}

data = {
    "doctype": "Journal Entry",
    "voucher_type": "Journal Entry",
    "posting_date": "2025-04-30",
    "accounts": [  # This is the child table field
        {
            "doctype": "Journal Entry Account",
            "account": "Cash - BPST",
            "debit_in_account_currency": 1000
        },
        {
            "doctype": "Journal Entry Account",
            "account": "Cash - BPST",
            "credit_in_account_currency": 1000
        }
    ]
}

res = requests.post("http://127.0.0.1:8001/api/resource/Journal Entry", json=data, headers=headers)
print(res.json())

Explanation:

  • Journal Entry is the parent doctype.
  • accounts is the child table field, which expects a list of Journal Entry Account records.
  • Each child item must also specify its doctype (Journal Entry Account) in the payload.
  • The Authorization header is required when using token-based auth.

hi @Sudhanshu, thanks for the reply.

but I think the code you gave will create a new entry in parent doctype (Journal Entry) and added child records in it. but I just want to insert a record in child table. Parent Doctype Record is already Created.
as per the example you give, I need to add a new “Journal Entry Account” for a particular Journal Entry, where Journal Entry is already Created.

Am I Correct?

i am thinking of using PUT request by sending parent doctype ID, so that new records will be inserted in Child Table

then use PUT for existing entry ,

PUT /api/resource/Journal Entry/ACC-JV-2025-00001

payload:

{
  "accounts": [
    {
      "doctype": "Journal Entry Account",
      "account": "Existing Account 1",
      "debit": 500
    },
    {
      "doctype": "Journal Entry Account",
      "account": "Cash - CO",
      "debit": 1000
    }
  ]
}