Answers.Body: <p>You can use chaining:</p>
  
  <pre><code>civicrm_api3('Contact', 'get', array(
    'return' =&gt; 'id', // more efficient since you don't care about the get results
    ... other search params ...
    'api.Contact.create' =&gt; array('last_name' =&gt; 'Something'),
  ));
  </code></pre>
  
  <p>The 'id' will be set for you automatically by the chaining. For more about chaining see <a href="https://civicrm.stackexchange.com/questions/17905/what-is-the-join-logic-when-using-api-chaining-with-action-get">this post</a>.</p>
  
  <p>Also remember the 'gotcha' that unless you specify otherwise, this will only fetch &amp; update 25 records.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-03-28T22:28:20.177Z
Answers.LastActivityDate: 2017-03-28T22:28:20.177Z
Answers.LastEditDate: 2017-04-13T12:53:13.017Z
Answers.UserDisplayName: Coleman
Body: <p>For doing updates to multiple contacts using the API, is there a better way than this?</p>
  
  <pre><code>$res = civicrm_api3('Contact', 'get', $params);
  foreach ($res['values'] as $contact) {
    civicrm_api3('Contact', 'create', array('id' =&gt; $contact['id'], ... ))
  }
  </code></pre>
  
  <p>For a large number of contacts, this is slow and eventually runs out of memory.</p>
  
Tags: <api>
Title: How to update multiple records with API?
ThreadText: # How to update multiple records with API?
  
  (Asked by: username_0 on 2017-03-27)
  
  For doing updates to multiple contacts using the API, is there a better way than this?
  
  ```
  $res = civicrm_api3('Contact', 'get', $params);
  foreach ($res['values'] as $contact) {
    civicrm_api3('Contact', 'create', array('id' => $contact['id'], ... ))
  }
  
  ```
  
  For a large number of contacts, this is slow and eventually runs out of memory.
  
  **Tags:** api
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2017-03-28. Score: 2
  
  You can use chaining:
  
  ```
  civicrm_api3('Contact', 'get', array(
    'return' => 'id', // more efficient since you don't care about the get results
    ... other search params ...
    'api.Contact.create' => array('last_name' => 'Something'),
  ));
  
  ```
  
  The 'id' will be set for you automatically by the chaining. For more about chaining see [this post](https://civicrm.stackexchange.com/questions/17905/what-is-the-join-logic-when-using-api-chaining-with-action-get).
  
  Also remember the 'gotcha' that unless you specify otherwise, this will only fetch & update 25 records.
  
  
  ---
  
  