Answers.Body: <p>Here is an example for creating a new email on an existing contact. Note that the default "Work" is location_type_id 2:</p>
  
  <pre><code>  $params = array(
      'contact_id' =&gt; 99,
      'location_type_id' =&gt; 2,
      'email' =&gt; 'myemail@work.com'
  
    try{
      $result = civicrm_api3('Email', 'create', $params);
    }
    catch (CiviCRM_API3_Exception $e) {
      // Handle error here.
      $errorMessage = $e-&gt;getMessage();
      $errorCode = $e-&gt;getErrorCode();
      $errorData = $e-&gt;getExtraParams();
      return array(
        'error' =&gt; $errorMessage,
        'error_code' =&gt; $errorCode,
        'error_data' =&gt; $errorData,
      );
    }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-18T01:25:23.000Z
Answers.Text: It's not necessary to pass option ids, as names will work just as well and are more readable, so you could write instead `'location_type_id' => 'Work'`
Answers.UserDisplayName: Coleman
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-17T23:00:21.973Z
Answers.LastActivityDate: 2015-08-17T23:00:21.973Z
Answers.UserDisplayName: Nicholai
Body: <p>I need to add an email id to a CiviCRM contact through the API. Existing email ids of the contact should be kept unchanged and the new email added as type "Work" (the contact doesn't have any "Work" emails yet, if that should make it easier).</p>
  
  <p>I tried to find a suitable API call through the API Explorer (civicrm/api/explorer) but the autocomplete didn't offer an Email field anywhere.</p>
  
  <p>I also found <a href="https://forum.civicrm.org/index.php?topic=9005.0" rel="nofollow">an old forum post</a> using some <code>civicrm_location_update($params)</code>. But this left me confused and I can't find anything like it in the API Explorer.</p>
  
Tags: <api>
Title: How can I add an additional email id for "work" through API?
ThreadText: # How can I add an additional email id for "work" through API?
  
  (Asked by: username_0 on 2015-08-17)
  
  I need to add an email id to a CiviCRM contact through the API. Existing email ids of the contact should be kept unchanged and the new email added as type "Work" (the contact doesn't have any "Work" emails yet, if that should make it easier).
  
  I tried to find a suitable API call through the API Explorer (civicrm/api/explorer) but the autocomplete didn't offer an Email field anywhere.
  
  I also found [an old forum post](https://forum.civicrm.org/index.php?topic=9005.0) using some `civicrm_location_update($params)`. But this left me confused and I can't find anything like it in the API Explorer.
  
  **Tags:** api
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-08-17. Score: 4 | Accepted answer
  
  Here is an example for creating a new email on an existing contact. Note that the default "Work" is location\_type\_id 2:
  
  ```
    $params = array(
      'contact_id' => 99,
      'location_type_id' => 2,
      'email' => 'myemail@work.com'
  
    try{
      $result = civicrm_api3('Email', 'create', $params);
    }
    catch (CiviCRM_API3_Exception $e) {
      // Handle error here.
      $errorMessage = $e->getMessage();
      $errorCode = $e->getErrorCode();
      $errorData = $e->getExtraParams();
      return array(
        'error' => $errorMessage,
        'error_code' => $errorCode,
        'error_data' => $errorData,
      );
    }
  
  ```
  
  > **Comments:**
  > **username_2**: It's not necessary to pass option ids, as names will work just as well and are more readable, so you could write instead `'location_type_id' => 'Work'`  
  
  ---
  
  