[Rest API] Fetch data in linked doctype

I have 2 doctypes, Agency and Category. Agency has field that linked to Category, meanwhile Category is a standalone. I need to fetch data in Agency along with category_name, not just the name/id. This is what I’ve tried:

{{erpnext.url}}/api/resource/Agency?fields=[“name”,“profile_img”,“fullname”,"tabCategory.category",“position”]&filters=[[“category”,"=",“f9c3093c05”]]

This works if Category is child of Agency. But I need Category to be a standalone. Is this possible?

Hi @hikmahaz,

I think is not possible if the Category is not linked with Agency because of how could to get a record without any link.

Thanks.

so if Category is not a child doctype it’s not possible? ok, thanks

Because it’s not connected to each other.

Thanks.

but Agency has a field that linked to Category tho. that alone is not enough?

Category field in parent doctype of Agency or child doctype of Agency?
If a link in the child doctype of the Agency then the name of the child table?

Maybe, if possible then there is more complexity to get data.

Thanks.

Agency: agency_name (data), address (text), category (link to Category)
Category: category_name (data), priority (int)

those were the fields on each doctype

Hi @hikmahaz,

{{erpnext.url}}/api/resource/Agency?fields=["category"]&filters=[["category","=","f9c3093c05"]]

only category id display only.

Otherwise, first, fetch category_name and priority from Category in a custom field in Agency Doctype then API set like

{{erpnext.url}}/api/resource/Agency?fields=["category_name"]&filters=[["category_name","=","Test1"]]

Thanks.