Create dynamic link at Address to Supplier and Client in Frappe Python Flask - LinkValidationError: Could not find Row

Hello,

Please help me!
My application is based on Python Flask and uses Frappe to communicate with ERP Next. There is a website that sends (client side) all the information to my Flask (python) app and then my application interact with various API included ERPNext. Everything is a design constraint.

The needs is to first create Customers /Suppliers and then add them the Address.
The creation of them is perfect and fully functional, but I cannot link the address to the customer/supplier during the address creation.
My Jsons are structured in this way:

  • Customer:
    {
    ‘doctype’: ‘Customer’,
    ‘customer_name’: ‘-the full name with internal codes-’,
    ‘first_name’: ‘-thename-’,
    ‘last_name’: ‘-thelastname-’,
    ‘email’: ‘-theemail-’,
    ‘mobile_phone_number’: ‘-thenumber-’,
    }

  • Address:
    {
    ‘doctype’: ‘Address’,
    ‘address_title’: ‘-the full name of customer-’
    …all the address information…
    ‘links’: [{‘link_doctype’: ‘Customer’,‘link_name’: -the full name with internal codes-'},
    {‘link_doctype’: ‘Supplier’,‘link_name’: ‘-thesuppliername-’}
    ]
    }

all the data between “-” are variable data

i receive the following error:
LinkValidationError: Could not find Row #1: Link Name: -thecustomername-

the Customer with customer_name: -thecustomername- exists in ERP
a very old version of the same app built in node.js was able to do this, but I cannot access to it.

I’m doing something wrong?
Should I add some reference to doctype ‘Address’ in ‘Customer’?

The address creation is successive to customer creation and i create the reference between the two models after or during address creation.
what do you suggest?

thanks a lot to everybody

This is a longshot, but have you tried to create the links separately as

{
  'doctype': 'Dynamic Link',
  'link_doctype': 'Customer',
  'link_name': customer_name,
  'parenttype': 'Address',
  'parent': address_name
}

Make sure that customer_name and address_name reflect the ids in ERPNext.

Maybe this helps…

Thanks a lot for your solution, yes it is a longshot…

Anyway your idea added some new information in my mind on ERPNext APIs.
Unfortunately even if I have checked for long time everything I got this error:
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

it seems related to my JSON - I paste here what I get from console doing “print”:

   { 'link_name':     '-customer-name-',
     'parenttype':    'Address', 
     'parent':        '-address-name-', 
     'link_doctype':  'Customer', 
     'doctype':       'Dynamic Link' }

(-customer-name- and -address-name- includes the real strings)

I don’t see anything really strange and it is very similar to the other JSONs I create in the rest of my app.
In order to add new items, I use the “insert” method of FrappeClient.

“insert method” of FrappeClient is defined in this way, and it includes json.dumps(doc) for JSON formatting:

def insert(self, doc):  
  res = self.session.post(self.url + "/api/resource/" + doc.get("doctype"),
                        data={"data": json.dumps(doc)})
  return self.post_process(res)

Above solution work only customer
but my problem is two side not show
means in customer show address and in contact Dynemic links also is emty :saluting_face: :smile: :smile:
after some hord work then make proper solution for add entry by “Document Api”

doc = frappe.get_doc({
‘doctype’: ‘Dynamic Link’,
‘link_doctype’: ‘Customer’,
‘link_name’: customer, // customer id
‘parenttype’: ‘Contact’,
‘parent’: contact, // contact id
‘parentfield’:‘links’,
‘link_title’:link_title // title
})
doc.insert()