Answers.Body: <p>so you are trying to fetch the details of contacts that are related to the ones you search for first?
  The $value refers to the last call in a nested one. </p>
  
  <pre><code>$result = civicrm_api3('Contact', 'get', array(
    'sequential' =&gt; 1,
    'return' =&gt; "id",
    'api.Relationship.get' 
     =&gt; array(
       'contact_id_a' =&gt; "\$value.id",
       'api.contact.get' =&gt; "\$value.contact_id_b"),
  ));
  </code></pre>
  
  <p>If you want to give more params to the inner api.contact.get:</p>
  
  <pre><code>$result = civicrm_api3('Contact', 'get', array(
    'sequential' =&gt; 1,
    'return' =&gt; "id",
    'api.Relationship.get' 
     =&gt; array('contact_id_a' =&gt; "\$value.id", 
       'api.contact.get' 
        =&gt; array(
          'id' =&gt; "\$value.contact_id_b", 
          'sequential' =&gt; 1, 
          'return' =&gt; "display_name"
        )
      ),
    )
  );
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-01-25T13:37:31.683Z
Answers.Text: Thanks a mil for response, Xavier. Shall have a closer look at it, since it has turned to be related to another question i've asked here http://civicrm.stackexchange.com/questions/9086/entityref-widget-seems-to-not-respecting-params : recent discoveries show, that there is same "id is not a proper integer"  error popped up. So, hopefully, cracking this one, both will be targeted and resolved.
Answers.UserDisplayName: yurg
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-01-25T08:38:19.400Z
Answers.LastActivityDate: 2016-01-25T08:45:01.617Z
Answers.LastEditDate: 2016-01-25T08:45:01.617Z
Answers.UserDisplayName: Xavier
Body: <p>While making a cascade API call, a roadblock has been hit, here's a code:</p>
  
  <pre><code>$result = civicrm_api3('Contact', 'get', array(
    'sequential' =&gt; 1,
    'return' =&gt; "id",
    'id' =&gt; array('IN' =&gt; array(168, 169)),
  
   // Second call
  
      'api.Relationship.get' =&gt; array(
        'return' =&gt; "contact_id_a",
        'contact_id_b' =&gt; "\$value.id",
        'relationship_type_id' =&gt; 4,
        'is_permission_b_a' =&gt; "1"),
  
            // Third call
  
          'api.Contact.get' =&gt; array('id' =&gt; array(
             'IN' =&gt; array("\$value.api.relationship.get"))), // &lt;-- here
  )); 
  </code></pre>
  
  <p>It returns </p>
  
  <pre><code>{
      "error_field": "id",
      "type": "integer",
      "error_code": 2001,
      "entity": "Contact",
      "action": "get",
      "is_error": 1,
      "error_message": "Error in call to Contact_get : id is not a valid integer"
  }
  </code></pre>
  
  <p>What exactly returns third call and how these results should be properly "plugged in" to get correct output? Thanks anyone for any bit of advice! </p>
  
Tags: <api><relationships><developer><chaining>
Title: Chain API call cascade, pass second value as third call argument, "id is not a valid integer"
ThreadText: # Chain API call cascade, pass second value as third call argument, "id is not a valid integer"
  
  (Asked by: username_0 on 2016-01-23)
  
  While making a cascade API call, a roadblock has been hit, here's a code:
  $result = civicrm_api3('Contact', 'get', array(
    'sequential' => 1,
    'return' => "id",
    'id' => array('IN' => array(168, 169)),
  
   // Second call
  
      'api.Relationship.get' => array(
        'return' => "contact_id_a",
        'contact_id_b' => "\$value.id",
        'relationship_type_id' => 4,
        'is_permission_b_a' => "1"),
  
            // Third call
  
          'api.Contact.get' => array('id' => array(
             'IN' => array("\$value.api.relationship.get"))), // <-- here
  )); 
  
  It returns 
  {
      "error_field": "id",
      "type": "integer",
      "error_code": 2001,
      "entity": "Contact",
      "action": "get",
      "is_error": 1,
      "error_message": "Error in call to Contact_get : id is not a valid integer"
  }
  
  What exactly returns third call and how these results should be properly "plugged in" to get correct output? Thanks anyone for any bit of advice!
  
  **Tags:** api, relationships, developer, chaining
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-01-25. Score: 1 | Accepted answer
  
  so you are trying to fetch the details of contacts that are related to the ones you search for first?
  The $value refers to the last call in a nested one. 
  $result = civicrm_api3('Contact', 'get', array(
    'sequential' => 1,
    'return' => "id",
    'api.Relationship.get' 
     => array(
       'contact_id_a' => "\$value.id",
       'api.contact.get' => "\$value.contact_id_b"),
  ));
  
  If you want to give more params to the inner api.contact.get:
  $result = civicrm_api3('Contact', 'get', array(
    'sequential' => 1,
    'return' => "id",
    'api.Relationship.get' 
     => array('contact_id_a' => "\$value.id", 
       'api.contact.get' 
        => array(
          'id' => "\$value.contact_id_b", 
          'sequential' => 1, 
          'return' => "display_name"
        )
      ),
    )
  );
  
  > **Comments:**
  > **username_0**: Thanks a mil for response, username_1. Shall have a closer look at it, since it has turned to be related to another question i've asked here http://civicrm.stackexchange.com/questions/9086/entityref-widget-seems-to-not-respecting-params : recent discoveries show, that there is same "id is not a proper integer"  error popped up. So, hopefully, cracking this one, both will be targeted and resolved.  
  
  ---
  
  