Answers.Body: <p>Ideally I would be using the $value.contact_id var but I can't get it to work that way. </p>
  
  <p>membership->tags (via contact_id)</p>
  
  <p>What I did get working was inserting a 3rd link in the api call chain. </p>
  
  <p>membership->contact->tags</p>
  
  <pre><code>CRM.api3('Membership', 'get', {
    "sequential": 1,
    "status_id": "Current",
    "options": {"limit":0},
    "contact_id.contact_type": "Organization",
    "api.Contact.get": {"api.EntityTag.get":{}}
  }).done(function(result) {
    // do something
  });
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-09-01T17:23:56.570Z
Answers.Text: A little late but just perused this... might be obvious to others but in case it's helpful... to get $value.contact_id working I had to escape the $. So my chained call looked like 'api.Contact.get' => array('id' => "\$value.contact_id", etc
Answers.UserDisplayName: Eli Lisseck
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-04-24T05:23:24.377Z
Answers.LastActivityDate: 2016-04-24T05:23:24.377Z
Answers.UserDisplayName: Derek
Answers.Body: <p>First, you need to do chained api call, like you did with :</p>
  
  <pre><code>"api.Contact.get": { "sequential": 1, "api.EntityTag.get":{}}
  </code></pre>
  
  <p>Second, you can filter the result of your chained call by doing so :</p>
  
  <pre><code>"$value.api.Contact.get.contact_type": "Organization"
  </code></pre>
  
  <p>Third, to get the result of your chained api call, you need to do something like :</p>
  
  <pre><code>tags = result['values'][0]['api.Contact.get']['values'][0]['api.EntityTag.get']['values'];
  </code></pre>
  
  <p>If you want something a little less complex, you can use <code>getsingle</code> or <code>getvalue</code> instead of get. This way, you won't have to loop on <code>values</code></p>
  
  <p>So the final result should look like :</p>
  
  <pre><code>CRM.api3('Membership', 'get', {
    "sequential": 1,
    "api.Contact.getsingle": {
      "api.EntityTag.get" : {}
    }
    "status_id": "Current",
    "$value.api.Contact.getsingle.contact_type": "Organization"  // instead of contact_id.contact_type
  }).done(function(result) {
    // replace by a loop on membership...
    tags = result['values'][0]['api.Contact.getsingle']['api.EntityTag.get']['values'];
  });
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-05-04T13:25:22.260Z
Answers.LastActivityDate: 2016-05-04T13:25:22.260Z
Answers.UserDisplayName: samuelsov
Body: <p>I am looking to get a list of all contacts with active memberships, and their respective tags.  I went about this by starting from an api call to give me all current memberships owned by a company. </p>
  
  <pre><code>CRM.api3('Membership', 'get', {
    "sequential": 1,
    "return": ["contact_id.tag","contact_id.id"],
    "status_id": "Current",
    "contact_id.contact_type": "Organization"
  }).done(function(result) {
    // do something
  });
  </code></pre>
  
  <p>Running the above only gets me the default returns vals of the contact_id and id of the membership. It does not return the tags. </p>
  
  <p>When I run this by itself: </p>
  
  <pre><code>$result = civicrm_api3('EntityTag', 'getsingle', array(
    'sequential' =&gt; 1,
    'contact_id' =&gt; 137402,
  ));
  </code></pre>
  
  <p>I get what I want, the tag ids for the contact. </p>
  
  <p>What am I doing wrong here? </p>
  
Tags: <civimember><api><tags>
Title: Chained API Call : Membership.contact_id EntityTags
ThreadText: # Chained API Call : Membership.contact_id EntityTags
  
  (Asked by: username_0 on 2016-04-24)
  
  I am looking to get a list of all contacts with active memberships, and their respective tags. I went about this by starting from an api call to give me all current memberships owned by a company.
  
  ```
  CRM.api3('Membership', 'get', {
    "sequential": 1,
    "return": ["contact_id.tag","contact_id.id"],
    "status_id": "Current",
    "contact_id.contact_type": "Organization"
  }).done(function(result) {
    // do something
  });
  
  ```
  
  Running the above only gets me the default returns vals of the contact\_id and id of the membership. It does not return the tags.
  
  When I run this by itself:
  
  ```
  $result = civicrm_api3('EntityTag', 'getsingle', array(
    'sequential' => 1,
    'contact_id' => 137402,
  ));
  
  ```
  
  I get what I want, the tag ids for the contact.
  
  What am I doing wrong here?
  
  **Tags:** civimember, api, tags
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_0 on 2016-04-24. Score: 1
  
  Ideally I would be using the $value.contact\_id var but I can't get it to work that way.
  
  membership->tags (via contact\_id)
  
  What I did get working was inserting a 3rd link in the api call chain.
  
  membership->contact->tags
  
  ```
  CRM.api3('Membership', 'get', {
    "sequential": 1,
    "status_id": "Current",
    "options": {"limit":0},
    "contact_id.contact_type": "Organization",
    "api.Contact.get": {"api.EntityTag.get":{}}
  }).done(function(result) {
    // do something
  });
  
  ```
  
  > **Comments:**
  > **username_1**: A little late but just perused this... might be obvious to others but in case it's helpful... to get $value.contact_id working I had to escape the $. So my chained call looked like 'api.Contact.get' => array('id' => "\$value.contact_id", etc  
  
  ---
  
  ### Answer by username_2 on 2016-05-04. Score: 1
  
  First, you need to do chained api call, like you did with :
  
  ```
  "api.Contact.get": { "sequential": 1, "api.EntityTag.get":{}}
  
  ```
  
  Second, you can filter the result of your chained call by doing so :
  
  ```
  "$value.api.Contact.get.contact_type": "Organization"
  
  ```
  
  Third, to get the result of your chained api call, you need to do something like :
  
  ```
  tags = result['values'][0]['api.Contact.get']['values'][0]['api.EntityTag.get']['values'];
  
  ```
  
  If you want something a little less complex, you can use `getsingle` or `getvalue` instead of get. This way, you won't have to loop on `values`
  
  So the final result should look like :
  
  ```
  CRM.api3('Membership', 'get', {
    "sequential": 1,
    "api.Contact.getsingle": {
      "api.EntityTag.get" : {}
    }
    "status_id": "Current",
    "$value.api.Contact.getsingle.contact_type": "Organization"  // instead of contact_id.contact_type
  }).done(function(result) {
    // replace by a loop on membership...
    tags = result['values'][0]['api.Contact.getsingle']['api.EntityTag.get']['values'];
  });
  
  ```
  
  
  ---
  
  