Add emails to Contact with REST API


I’m accessing the REST API via python, I can retrieve a Contact record and make changes to the standard fields. Having looked at the FrappeClient examples I can also access the list of email addresses. However I can’t see a way of adding a new email address to a Contact.

My current code is:

from frappeclient import FrappeClient

client = FrappeClient('*******','********','*******')

doc = client.get_doc("Contact", contact['name'])
emails = doc.get('email_ids')
for email in emails:
    print('Email Address : ' + email['email_id'])
    print('Is Primary : ' + str(email['is_primary']==1))

Not sure how to update or add new email addresses to the Contact record.


Solved it, for reference for anyone else looking.

doc = client.get_doc("Contact", 'contact name')
emails = doc.get('email_ids')
new_email = {
    'email_id': '', 
    'is_primary': 0, 
    'doctype': 'Contact Email'

There may well be a better way of doing this?