Custom Api - Rest APi - Doctype and Child Doctype data

I write this code as a custom api to get all data from doctype without login. Turiya has a child doctype[TuriyaData] that doctype value is fully null. how to get the data like api/resource/turiya

@frappe.whitelist(allow_guest=True)
def get_turiya_data():
data = frappe.db.get_all(‘Turiya’, filters={‘name’: id}, fields=[‘*’] )
return data

Hi @Ramki_Marichamy,

Please check and apply it.
We did try on lead. and get the data successfully.

import frappe

@frappe.whitelist(allow_guest=True)
def get_doctype_data():
    data = frappe.db.get_all("Lead")
    return data

Without login

URL:

/api/method/custom_app.api_file_name.get_lead_data

Thank You!

1 Like

Hi bro,
thank you for the reply. I am also getting the data for Turiya.
But Turiya has child doctype that child data is fully null. without joint the parent and child doctype can we get the data fully like api/resource/turiya

You can’t get the child table data without a parent.
If parent data then will display the data of the child table.

But you can define it like this if you comfortable with it.
Without id:

import frappe

@frappe.whitelist(allow_guest=True)
def get_so_data():
    data = frappe.db.get_all('Sales Order', fields="`tabSales Order Item`.item_code,`tabSales Order Item`.qty")
    return data

Then will only show the child table data of all sales orders.

Maybe it will become helpful for you.
Thank You!

Thank you!
The above code is working. It gives the child doctype data. I want both Parent and Child doctype data combined. how to get

Please apply like this:

import frappe

@frappe.whitelist(allow_guest=True)
def get_so_data():
    data = frappe.db.get_all('Sales Order', fields="name, customer, `tabSales Order Item`.item_code,`tabSales Order Item`.qty")
    return data

Then check it.

Thank You!

1 Like

Do you have any post custom api example for parent and child doctype

Thank you So much @NCP

The above code is an example of a custom API with added to the custom app.

Please try on custom doctype, I think it will 100% work.

Have a good day!
Thank You!

1 Like