2

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!

1 Answer 1

1

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"
      )
    ),
  )
);
1
  • 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 civicrm.stackexchange.com/questions/9086/… : 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.
    – yurg
    Commented Jan 25, 2016 at 13:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.