Answers.Body: <p>I got what I needed by including the email id (<strong>&quot;id&quot;:2</strong>) in the records chain property:</p>
  <pre><code>crmApi4('Contact', 'save', {
    records: [{&quot;id&quot;:2, &quot;first_name&quot;:&quot;Mike&quot;}],
    chain: {&quot;name_me_0&quot;:[&quot;Email&quot;, &quot;save&quot;, {&quot;records&quot;:[{&quot;contact_id&quot;:&quot;$id&quot;, &quot;email&quot;:&quot;mike@agloa.org&quot;, &quot;id&quot;:2}]}]}
  })
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-07-18T21:26:02.033Z
Answers.LastActivityDate: 2021-07-18T21:26:02.033Z
Answers.UserDisplayName: MikeSteigerwald
Body: <p>Using civicrm api4, what's the best way to chain save a contact so that the email updates, without creating a new one?</p>
  <p>For example, I want to update this existing contact:</p>
  <pre><code>entity: Contact, action: get, version: 4, count: 1
  (1) [
    {
      &quot;id&quot;: 2,
      &quot;first_name&quot;: &quot;Michael&quot;,
      &quot;email.email&quot;: &quot;cio@agloa.org&quot;
    }
  ]
  </code></pre>
  <p>... to have first_name: &quot;Mike&quot; and email: &quot;mike@agloa.org&quot;. So, I tried:</p>
  <pre><code>crmApi4('Contact', 'save', {
    records: [{&quot;id&quot;:2, &quot;first_name&quot;:&quot;Mike&quot;}],
    chain: {&quot;name_me_0&quot;:[&quot;Email&quot;, &quot;save&quot;, {&quot;records&quot;:[{&quot;contact_id&quot;:&quot;$id&quot;, &quot;email&quot;:&quot;mike@agloa.org&quot;}]}]}
  })
  </code></pre>
  <p>That correctly updates the first name, but <em>creates</em> a new email:</p>
  <pre><code>entity: Contact, action: get, version: 4, count: 2
  (2) [
    {
      &quot;id&quot;: 2,
      &quot;first_name&quot;: &quot;Mike&quot;,
      &quot;email.id&quot;: 2,
      &quot;email.email&quot;: &quot;cio@agloa.org&quot;
    },
    {
      &quot;id&quot;: 2,
      &quot;first_name&quot;: &quot;Mike&quot;,
      &quot;email.id&quot;: 11,
      &quot;email.email&quot;: &quot;mike@agloa.org&quot;
    }
  ]
  </code></pre>
  <p>How can I get it to simply update the existing email?</p>
  
Tags: <chaining><apiv4>
Title: Best (api4) way to chain save a contact so that the email updates, without creating a new one?
ThreadText: # Best (api4) way to chain save a contact so that the email updates, without creating a new one?
  
  (Asked by: username_0 on 2021-06-20)
  
  Using civicrm api4, what's the best way to chain save a contact so that the email updates, without creating a new one?
  
  For example, I want to update this existing contact:
  
  ```
  entity: Contact, action: get, version: 4, count: 1
  (1) [
    {
      "id": 2,
      "first_name": "Michael",
      "email.email": "cio@agloa.org"
    }
  ]
  
  ```
  
  ... to have first\_name: "Mike" and email: "mike@agloa.org". So, I tried:
  
  ```
  crmApi4('Contact', 'save', {
    records: [{"id":2, "first_name":"Mike"}],
    chain: {"name_me_0":["Email", "save", {"records":[{"contact_id":"$id", "email":"mike@agloa.org"}]}]}
  })
  
  ```
  
  That correctly updates the first name, but *creates* a new email:
  
  ```
  entity: Contact, action: get, version: 4, count: 2
  (2) [
    {
      "id": 2,
      "first_name": "Mike",
      "email.id": 2,
      "email.email": "cio@agloa.org"
    },
    {
      "id": 2,
      "first_name": "Mike",
      "email.id": 11,
      "email.email": "mike@agloa.org"
    }
  ]
  
  ```
  
  How can I get it to simply update the existing email?
  
  **Tags:** chaining, apiv4
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2021-07-18. Score: 2 | Accepted answer
  
  I got what I needed by including the email id (**"id":2**) in the records chain property:
  
  ```
  crmApi4('Contact', 'save', {
    records: [{"id":2, "first_name":"Mike"}],
    chain: {"name_me_0":["Email", "save", {"records":[{"contact_id":"$id", "email":"mike@agloa.org", "id":2}]}]}
  })
  
  ```
  
  
  ---
  
  