Customer Creation: "Unknown column 'doctype' in 'where clause'

Hello,

I’m trying to integrate ERPNext with E-commerce platform I have created endpoint for creating Customer as below:

erp_customer = payload.get("erp_customer")
new_customer = frappe.get_doc(erp_customer) 
# Object is created and I can check its attributes 

# Below line is throwing errors
new_customer.insert(ignore_mandatory=True, ignore_permissions=True)

new_customer.save()
new_customer.submit()
frappe.db.commit()

Side note: I have successfully Created Order, Addresses, Products via API I have problem just with two Tables Contact and Customer, which are throwing the same error.
Input I’m sending:

"erp_customer": {
        "accounts": [],
        "companies": [],
        "credit_limits": [],
        "customer_name": "VXNlcjoyMDg0NTEwNDQy",
        "customer_primary_address": {
            "address_line2": "",
            "address_title": "QWRkcmVzczozODY=",
            "address_type": "Shipping",
            "city": "PILA",
            "country": "Poland",
            "doctype": "Address",
            "name": "QWRkcmVzczozODY=-Shipping",
            "pincode": "99-999",
            "primary_address": "112 Lelewela",
            "state": ""
        },
        "customer_type": "Individual",
        "doctype": "Customer",
        "disabled": 0,
        "dn_required": 0,
        "is_frozen": 0,
        "is_internal_customer": 0,
        "language": "en",
        "name": "VXNlcjoyMDg0NTEwNDQy",
        "naming_series": "CUST-.YYYY.-",
        "owner": "Administrator",
        "portal_users": [],
        "primary_address": "112 Lelewela<br>\nPILA<br>\nPoland<br>\n<br>/n",
        "sales_team": [],
        "so_required": 0
    }

Error I’m getting:
"pymysql.err.OperationalError: (1054, "Unknown column ‘doctype’ in ‘where clause’")

Full Traceback of issue:
“["Traceback (most recent call last):\n File \"apps/frappe/frappe/app.py\", line 110, in application\n response = frappe.api.handle(request)\n ^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"apps/frappe/frappe/api/init.py\", line 49, in handle\n data = endpoint(**arguments)\n ^^^^^^^^^^^^^^^^^^^^^\n File \"apps/frappe/frappe/api/v1.py\", line 36, in handle_rpc_call\n return frappe.handler.handle()\n ^^^^^^^^^^^^^^^^^^^^^^^\n File \"apps/frappe/frappe/handler.py\", line 49, in handle\n data = execute_cmd(cmd)\n ^^^^^^^^^^^^^^^^\n File \"apps/frappe/frappe/handler.py\", line 85, in execute_cmd\n return frappe.call(method, **frappe.form_dict)\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"apps/frappe/frappe/init.py\", line 1682, in call\n return fn(*args, **newargs)\n ^^^^^^^^^^^^^^^^^^^^\n File \"apps/frappe/frappe/utils/typing_validations.py\", line 31, in wrapper\n return func(*args, **kwargs)\n ^^^^^^^^^^^^^^^^^^^^^\n File \"local_apps/erpnext-feeds/erp_feeds/api.py\", line 216, in create_order\n populate_customer_in_db(payload)\n File \"local_apps/erpnext-feeds/erp_feeds/api.py\", line 141, in populate_customer_in_db\n new_customer.insert(ignore_mandatory=True, ignore_permissions=True) # tutaj cos z nazwa kolumny \"Customer\"?\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"apps/frappe/frappe/model/document.py\", line 278, in insert\n self._validate_links()\n File \"apps/frappe/frappe/model/document.py\", line 913, in _validate_links\n invalid_links, cancelled_links = self.get_invalid_links()\n ^^^^^^^^^^^^^^^^^^^^^^^^\n File \"apps/frappe/frappe/model/base_document.py\", line 780, in get_invalid_links\n values = _dict(name=frappe.db.get_value(doctype, docname, \"name\", cache=True))\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"apps/frappe/frappe/database/database.py\", line 516, in get_value\n result = self.get_values(\n ^^^^^^^^^^^^^^^^\n File \"apps/frappe/frappe/database/database.py\", line 617, in get_values\n out = self._get_values_from_table(\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"apps/frappe/frappe/database/database.py\", line 884, in _get_values_from_table\n return query.run(as_dict=as_dict, debug=debug, update=update, run=run, pluck=pluck)\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"apps/frappe/frappe/query_builder/utils.py\", line 87, in execute_query\n result = frappe.db.sql(query, params, *args, **kwargs) # nosemgrep\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"apps/frappe/frappe/database/database.py\", line 235, in sql\n self._cursor.execute(query, values)\n File \"env/lib/python3.11/site-packages/pymysql/cursors.py\", line 153, in execute\n result = self._query(query)\n ^^^^^^^^^^^^^^^^^^\n File \"env/lib/python3.11/site-packages/pymysql/cursors.py\", line 322, in _query\n conn.query(q)\n File \"env/lib/python3.11/site-packages/pymysql/connections.py\", line 558, in query\n self._affected_rows = self._read_query_result(unbuffered=unbuffered)\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"env/lib/python3.11/site-packages/pymysql/connections.py\", line 822, in _read_query_result\n result.read()\n File \"env/lib/python3.11/site-packages/pymysql/connections.py\", line 1200, in read\n first_packet = self.connection._read_packet()\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"env/lib/python3.11/site-packages/pymysql/connections.py\", line 772, in _read_packet\n packet.raise_for_error()\n File \"env/lib/python3.11/site-packages/pymysql/protocol.py\", line 221, in raise_for_error\n err.raise_mysql_exception(self._data)\n File \"env/lib/python3.11/site-packages/pymysql/err.py\", line 143, in raise_mysql_exception\n raise errorclass(errno, errval)\npymysql.err.OperationalError: (1054, \"Unknown column ‘doctype’ in ‘where clause’\")\n"]”