Answers.Body: <p>A few advices :</p>
  
  <ul>
  <li>when you chain, you shouldn't have to define the entity_table. If you want to define it anyway, the entity_table should be the database table - i.e. <code>civicrm_contact</code> in your case.</li>
  <li>Label and id of the tag can be used in tag_id but i really encourage you to use the id. The label can change or be language dependent while the <code>id</code> could not change.</li>
  </ul>
  
  <p>But to answer your question, in your case, the real problem is the array part. The EntityTag api is to create one tag assignation. I don't think there is a syntax to assign multiple tag.</p>
  
  <p>It could be nice to be able to add several <code>api.EntityTag.create</code> but because the key is the api call definition, it's impossible right now (or i don't know how).</p>
  
  <p>So while this will work fine :</p>
  
  <pre><code>$result = civicrm_api3('Contact', 'create', array(
    'contact_type' =&gt; "Individual",
    'first_name' =&gt; "xxx",
    'last_name' =&gt; "yyy",
    'api.EntityTag.create' =&gt; array('tag_id' =&gt; 5),
  ));
  </code></pre>
  
  <p>If you have multiple tags, i suggest you do :</p>
  
  <pre><code>$result = civicrm_api3('Contact', 'create', array(
    'contact_type' =&gt; "Individual",
    'first_name' =&gt; "xxx",
    'last_name' =&gt; "yyy",
  ));
  $contact_id = $result['id'];
  foreach ($tags as $tag_id) {
    civicrm_api3('EntityTag', 'create', array(
      'entity_table' =&gt; 'civicrm_contact',
      'entity_id' =&gt; $contact_id,
      'tag_id' =&gt; $tag_id,
    );
  }
  </code></pre>
  
  <p><strong>EDIT</strong></p>
  
  <p>For multiple tags, you could try (not tested but work for website for example - <a href="https://github.com/civicrm/civicrm-core/blob/master/api/v3/examples/Contact/ChainTwoWebsites.php" rel="nofollow">https://github.com/civicrm/civicrm-core/blob/master/api/v3/examples/Contact/ChainTwoWebsites.php</a>)</p>
  
  <pre><code>$result = civicrm_api3('Contact', 'create', array(
    'contact_type' =&gt; "Individual",
    'first_name' =&gt; "xxx",
    'last_name' =&gt; "yyy",
    'api.EntityTag.create' =&gt; array('tag_id' =&gt; 5),
    'api.EntityTag.create.2' =&gt; array('tag_id' =&gt; 8),
  ));
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-02-01T15:04:35.047Z
Answers.LastActivityDate: 2016-05-17T19:53:33.277Z
Answers.LastEditDate: 2016-05-17T19:53:33.277Z
Answers.UserDisplayName: samuelsov
Body: <p>I am struggling with adding tags trough the CiviCRM API to a newly created contact in an extension (trough API Chaining). The installation is running on Wordpress 4.4.1 with CiviCRM 4.7. The following PHP snippet creates the contact with Tag "Non-Profit" which is not the expected behavior.</p>
  
  <pre><code>$contactParams['api.EntityTag.create'] = array(
          'entity_table' =&gt; 'Contacts', 'tag_id' =&gt; array("Interessent",     "Contributor")
  );
  
  $api-&gt;Contact-&gt;Create($contactParams)
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-01-30T22:12:15.770Z
Comments.Text: Could you please update your question with your CiviCRM version number?  If nothing else, I changed the behavior of the EntityTag API in https://issues.civicrm.org/jira/browse/CRM-17350, so this may be version-dependent.  Also, are you using a non-administrator account?  If so, you'll want to be using 4.7+ or merge in CRM-17350's patch.
Comments.UserDisplayName: Jon G - Megaphone Tech
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-01-31T00:05:48.190Z
Comments.Text: I am using 4.7. This is running as an extensions which hooks into civicrm_emailProcessor. I am not sure if the administrator account is relevant at all. The questions is, do I use the TagName or the TagID or Name_ID like the GroupContact API asks? I have tried all combinations with no success. The interesting thing is that the give example adds one unrelated tag named NonProfit with ID 1.
Comments.UserDisplayName: Alain Schaefer
Tags: <api>
Title: Which value to use for tag_id to create EntityTag
ThreadText: # Which value to use for tag_id to create EntityTag
  
  (Asked by: username_0 on 2016-01-30)
  
  I am struggling with adding tags trough the CiviCRM API to a newly created contact in an extension (trough API Chaining). The installation is running on Wordpress 4.4.1 with CiviCRM 4.7. The following PHP snippet creates the contact with Tag "Non-Profit" which is not the expected behavior.
  $contactParams['api.EntityTag.create'] = array(
          'entity_table' => 'Contacts', 'tag_id' => array("Interessent",     "Contributor")
  );
  
  $api->Contact->Create($contactParams)
  
  **Tags:** api
  
  > **Comments:**
  > **username_1**: Could you please update your question with your CiviCRM version number?  If nothing else, I changed the behavior of the EntityTag API in https://issues.civicrm.org/jira/browse/CRM-17350, so this may be version-dependent.  Also, are you using a non-administrator account?  If so, you'll want to be using 4.7+ or merge in CRM-17350's patch.  
  > **username_0**: I am using 4.7. This is running as an extensions which hooks into civicrm_emailProcessor. I am not sure if the administrator account is relevant at all. The questions is, do I use the TagName or the TagID or Name_ID like the GroupContact API asks? I have tried all combinations with no success. The interesting thing is that the give example adds one unrelated tag named NonProfit with ID 1.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2016-02-01. Score: 3 | Accepted answer
  
  A few advices :
  
  when you chain, you shouldn't have to define the entity_table. If you want to define it anyway, the entity_table should be the database table - i.e. civicrm_contact in your case.
  Label and id of the tag can be used in tag_id but i really encourage you to use the id. The label can change or be language dependent while the id could not change.
  
  But to answer your question, in your case, the real problem is the array part. The EntityTag api is to create one tag assignation. I don't think there is a syntax to assign multiple tag.
  It could be nice to be able to add several api.EntityTag.create but because the key is the api call definition, it's impossible right now (or i don't know how).
  So while this will work fine :
  $result = civicrm_api3('Contact', 'create', array(
    'contact_type' => "Individual",
    'first_name' => "xxx",
    'last_name' => "yyy",
    'api.EntityTag.create' => array('tag_id' => 5),
  ));
  
  If you have multiple tags, i suggest you do :
  $result = civicrm_api3('Contact', 'create', array(
    'contact_type' => "Individual",
    'first_name' => "xxx",
    'last_name' => "yyy",
  ));
  $contact_id = $result['id'];
  foreach ($tags as $tag_id) {
    civicrm_api3('EntityTag', 'create', array(
      'entity_table' => 'civicrm_contact',
      'entity_id' => $contact_id,
      'tag_id' => $tag_id,
    );
  }
  
  EDIT
  For multiple tags, you could try (not tested but work for website for example - https://github.com/civicrm/civicrm-core/blob/master/api/v3/examples/Contact/ChainTwoWebsites.php)
  $result = civicrm_api3('Contact', 'create', array(
    'contact_type' => "Individual",
    'first_name' => "xxx",
    'last_name' => "yyy",
    'api.EntityTag.create' => array('tag_id' => 5),
    'api.EntityTag.create.2' => array('tag_id' => 8),
  ));
  
  
  ---
  
  