Add emails to Contact with REST API

Hi,

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))
    print('--------------------------------------') 

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

Thanks

Solved it, for reference for anyone else looking.

doc = client.get_doc("Contact", 'contact name')
emails = doc.get('email_ids')
new_email = {
    'email_id': 'email.address@example.com', 
    'is_primary': 0, 
    'doctype': 'Contact Email'
}
emails.append(new_email)
client.update(doc)

There may well be a better way of doing this?