How to create DocType via REST API JSON response?

Hello Team,
I need to create dynamic DocType based on the REST API JSON response.
Could you please help me here, how should I achieve this?
Jitendra Tilekar.

Hi @jitendra.tilekar,

If you haven’t checked then check it, please.




Hi @NCP,

Here I am explaining my case:

URL : http:///api/getcustomerdata
JSON Response:

Based on the above JSON response I need to create a new DocType via python code, so how should I create a dynamic DocType with the above 4 fields?

If my API’s JSON response changed to:

JSON Response:
“Name”:“Jitendra Tilekar”,

So based on the above JSON response, the existing DocType should be changed with the above 3 fields.

for the reference

client = frappe.get_doc(dict(
	doctype = 'Customer',
	first_name = "Test",
	last_name = "Name"

Set you according to value and field name.


Hi @NCP,

My code:

class BankAPITest(Document):
	def createDoc(bean):
		client = frappe.get_doc(dict(
			doctype = 'Bank-API-Test',
			bankcode = bean

I have tried the above example but I have got the below error:

File "apps/frappe/frappe/modules/", line 235, in load_doctype_module
  doctype_python_modules[key] = frappe.get_module(module_name)
File "apps/frappe/frappe/", line 1236, in get_module
  return importlib.import_module(modulename)
File "/usr/local/Cellar/python@3.9/3.9.12/Frameworks/Python.framework/Versions/3.9/lib/python3.9/importlib/", line 127, in import_module
  return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 850, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "apps/demo_app/demo_app/demo_app/doctype/bank_api_test/", line 11, in <module>
  class BankAPITest(Document):
File "apps/demo_app/demo_app/demo_app/doctype/bank_api_test/", line 84, in BankAPITest
File "apps/demo_app/demo_app/demo_app/doctype/bank_api_test/", line 16, in createDoc
  client = frappe.get_doc(dict(
File "apps/frappe/frappe/", line 1115, in get_doc
  doc = frappe.model.document.get_doc(*args, **kwargs)
File "apps/frappe/frappe/model/", line 72, in get_doc
  controller = get_controller(doctype)
File "apps/frappe/frappe/model/", line 62, in get_controller
  return _get_controller()
File "apps/frappe/frappe/model/", line 58, in _get_controller
  raise ImportError(doctype)
ImportError: Bank-API-Test

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "apps/frappe/frappe/", line 67, in application
  response = frappe.api.handle()
File "apps/frappe/frappe/", line 54, in handle
  return frappe.handler.handle()
File "apps/frappe/frappe/", line 38, in handle
  data = execute_cmd(cmd)
File "apps/frappe/frappe/", line 76, in execute_cmd
  return, **frappe.form_dict)
File "apps/frappe/frappe/", line 1493, in call
  return fn(*args, **newargs)
File "apps/frappe/frappe/desk/form/", line 79, in getdoctype
  docs = get_meta_bundle(doctype)
File "apps/frappe/frappe/desk/form/", line 90, in get_meta_bundle
  bundle = [frappe.desk.form.meta.get_meta(doctype)]
File "apps/frappe/frappe/desk/form/", line 45, in get_meta
  meta = FormMeta(doctype)
File "apps/frappe/frappe/desk/form/", line 56, in __init__
File "apps/frappe/frappe/desk/form/", line 76, in load_assets
File "apps/frappe/frappe/desk/form/", line 225, in load_templates
  module = load_doctype_module(
File "apps/frappe/frappe/modules/", line 237, in load_doctype_module
  raise ImportError(
ImportError: Module import failed for Bank-API-Test (demo_app.demo_app.doctype.bank_api_test.bank_api_test Error: Bank-API-Test)

The sample response shows the response to the sample request. The response schema defines all possible elements in the response. The sample response is not exhaustive for all parameter configurations or operations but must match the parameters passed in the sample request. The answer allows developers to find out if the resource contains the information they want, the format and structure of the information, etc. The description of the response is sometimes also called the response scheme. The response schema documents the response in a more complete, generic way, listing each property that can be returned, what each property contains, the format of the value data, the structure, and other details. You can also refer to the website to learn more.