Answers.Body: <p>There are many ways you can update email for contact</p>
  
  <ol>
  <li><p>Using Email api with create action</p>
  
  <pre><code>CRM.api3('Email', 'create', {"email": "aaa@asas.comsdsd",  "id": 201}).done(function(result) { // do something});
  </code></pre></li>
  <li><p>Using Email api with replace action</p></li>
  </ol>
  
  <blockquote>
  <pre><code>  CRM.api3('Email', 'replace', {
        "values": {"0":{"email":"asasa@asas.com","location_typ_id":"Home"}},
        "contact_id": 203
      }).done(function(result) {
        // do something
      });
  </code></pre>
  </blockquote>
  
  <ol start="3">
  <li>Using Contact api with Email chain api</li>
  </ol>
  
  <blockquote>
  <pre><code>CRM.api3('Contact', 'create', {
    "id": 203,
    "api.Email.replace": {"values":{"0":{"email":"assdfsfdsasa@asas.com","location_typ_id":"Home"}}}
  }).done(function(result) {
    // do something
  });
  </code></pre>
  </blockquote>
  
  <p>HTH</p>
  
  <p>Pradeep</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-12T15:21:04.463Z
Answers.Text: 3. gave me what I needed. Adding the values object solved my problem. Many thanks!
Answers.UserDisplayName: Mike Steigerwald
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-16T17:23:28.037Z
Answers.Text: I could use some similar advise with Address chaining. This snippet (below) does what I need for email and phone, but not street_address. (No error, but nothing changes.) Is there different syntax I should use for address?
  
           crmApi('Contact', 'create', {
             id: myContact.id,
             last_name: myContact.last_name,
             "api.Email.replace": {"values":{"0":{"email":myContact.email}}},
             "api.Phone.replace": {"values":{"0":{"phone":myContact.phone}}},
             "api.Address.replace": {"values":{"0":{"street_address":myContact.street_address}}},
  
  etc.
Answers.UserDisplayName: Mike Steigerwald
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-16T17:37:32.927Z
Answers.Text: There is a limitation why people use 'replace' method to update email is it deletes all the emails before it creates one. So you have to make sure you pass all the emails in array that a contact has.
Answers.UserDisplayName: Pradeep Nayak
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-10T21:52:22.983Z
Answers.LastActivityDate: 2018-06-10T21:52:22.983Z
Answers.UserDisplayName: Pradeep Nayak
Answers.Body: <p>Email addresses are in their own separate entity in the API named "Email". You would update the email address with that using the contact ID to connect the person to the email address.</p>
  
  <p>Example from the API Explorer (from Civi 4.6):</p>
  
  <pre><code>CRM.api3('Email', 'create', {
    "contact_id": 1111,
    "email": "example@example.org"
  }).done(function(result) {
    // do something
  });
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-10T18:25:21.483Z
Answers.Text: Is that the best practice when I'm trying to update a contact's info with a single Save button? Shouldn't I try to use the chain API pattern?
Answers.UserDisplayName: Mike Steigerwald
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-12T17:46:08.373Z
Answers.Text: Glad you got it sorted!
Answers.UserDisplayName: Allen Hutchison
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-10T16:12:59.023Z
Answers.LastActivityDate: 2018-06-10T16:12:59.023Z
Answers.UserDisplayName: Allen Hutchison
Body: <p>I'm trying to update a contact and, especially, the email address. As far as I can tell using the API explorer, this is the correct JavaScript code for that:</p>
  
  <pre><code>            crmApi('Contact', 'create', {
            id: myContact.id,
            first_name: myContact.first_name,
            last_name: myContact.last_name,
            middle_name: myContact.middle_name,
            "api.Email": myContact.email
          })
  </code></pre>
  
  <p>It correctly updates the names, but not the email. Does anyone see what I have wrong?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-06-10T21:28:44.523Z
Comments.Text: have you tried to put "email" as the key?
Comments.UserDisplayName: Xavier
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-06-11T00:44:22.247Z
Comments.Text: "api.Email": myContact.email should be 
      "api.Email.create": myContact.email
Comments.UserDisplayName: user4278
Tags: <contacts><api><javascript>
Title: How to update contact email with JavaScript API?
ThreadText: # How to update contact email with JavaScript API?
  
  (Asked by: username_0 on 2018-06-10)
  
  I'm trying to update a contact and, especially, the email address. As far as I can tell using the API explorer, this is the correct JavaScript code for that:
              crmApi('Contact', 'create', {
            id: myContact.id,
            first_name: myContact.first_name,
            last_name: myContact.last_name,
            middle_name: myContact.middle_name,
            "api.Email": myContact.email
          })
  
  It correctly updates the names, but not the email. Does anyone see what I have wrong?
  
  **Tags:** contacts, api, javascript
  
  > **Comments:**
  > **username_1**: have you tried to put "email" as the key?  
  > **username_2**: "api.Email": myContact.email should be      "api.Email.create": myContact.email  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_3 on 2018-06-10. Score: 2 | Accepted answer
  
  There are many ways you can update email for contact
  
  Using Email api with create action
  CRM.api3('Email', 'create', {"email": "aaa@asas.comsdsd",  "id": 201}).done(function(result) { // do something});
  
  Using Email api with replace action
  
  
    CRM.api3('Email', 'replace', {
        "values": {"0":{"email":"asasa@asas.com","location_typ_id":"Home"}},
        "contact_id": 203
      }).done(function(result) {
        // do something
      });
  
  
  
  Using Contact api with Email chain api
  
  
  CRM.api3('Contact', 'create', {
    "id": 203,
    "api.Email.replace": {"values":{"0":{"email":"assdfsfdsasa@asas.com","location_typ_id":"Home"}}}
  }).done(function(result) {
    // do something
  });
  
  
  HTH
  Pradeep
  
  > **Comments:**
  > **username_0**: 3. gave me what I needed. Adding the values object solved my problem. Many thanks!  
  > **username_0**: I could use some similar advise with Address chaining. This snippet (below) does what I need for email and phone, but not street_address. (No error, but nothing changes.) Is there different syntax I should use for address?           crmApi('Contact', 'create', {            id: myContact.id,            last_name: myContact.last_name,            "api.Email.replace": {"values":{"0":{"email":myContact.email}}},            "api.Phone.replace": {"values":{"0":{"phone":myContact.phone}}},            "api.Address.replace": {"values":{"0":{"street_address":myContact.street_address}}},  etc.  
  > **username_3**: There is a limitation why people use 'replace' method to update email is it deletes all the emails before it creates one. So you have to make sure you pass all the emails in array that a contact has.  
  
  ---
  
  ### Answer by username_4 on 2018-06-10. Score: 0
  
  Email addresses are in their own separate entity in the API named "Email". You would update the email address with that using the contact ID to connect the person to the email address.
  Example from the API Explorer (from Civi 4.6):
  CRM.api3('Email', 'create', {
    "contact_id": 1111,
    "email": "example@example.org"
  }).done(function(result) {
    // do something
  });
  
  > **Comments:**
  > **username_0**: Is that the best practice when I'm trying to update a contact's info with a single Save button? Shouldn't I try to use the chain API pattern?  
  > **username_4**: Glad you got it sorted!  
  
  ---
  
  