Answers.Body: <p>Drush can read parameters from standard input in JSON format if you supply the argument <code>--in=json</code>. This is what we need for API chaining, because chaining uses nested parameters, and in contrast to a flat list of command line arguments (the default way to pass parameters to <code>drush cvapi</code>, JSON can handle nesting. So to retrieve the email addresses for contact ID 41194 along with that contact's display name, use:</p>
  
  <pre><code>echo '{
    "sequential": 1,
    "return": "display_name",
    "id": 41194,
    "api.Email.get": {"return":"email"}
  }' | drush cvapi Contact.getsingle --in=json
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-06-27T01:05:50.943Z
Answers.Text: This is good, with a couple caveats: the output is hard to parse, and it doesn't work on Joomla/WordPress. To resolve those issues, change `drush cvapi` to [`cv api`]( https://github.com/civicrm/cv). That notation works on more CMS's and supports better output formats (JSON, PHP serialize(), and sometimes CSV).
Answers.UserDisplayName: Tim Otten
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-01-31T01:39:20.327Z
Answers.LastActivityDate: 2017-01-31T01:44:33.757Z
Answers.LastEditDate: 2017-01-31T01:44:33.757Z
Answers.UserDisplayName: Noah Miller
Body: <p>API chaining works well in Javascript and PHP. For example, I can retrieve a contact's email addresses using this code generated by the API Explorer:</p>
  
  <p>Php</p>
  
  <pre><code>$result = civicrm_api3('Contact', 'getsingle', array(
    'sequential' =&gt; 1,
    'return' =&gt; "display_name",
    'id' =&gt; 41194,
    'api.Email.get' =&gt; array('return' =&gt; "email"),
  ));
  </code></pre>
  
  <p>Javascript  </p>
  
  <pre><code>CRM.api3('Contact', 'getsingle', {
    "sequential": 1,
    "return": "display_name",
    "id": 41194,
    "api.Email.get": {"return":"email"}
  }).done(function(result) {
    // do something
  });
  </code></pre>
  
  <p>However, the drush command generated by the API explorer doesn't work:</p>
  
  <pre><code>drush cvapi Contact.getsingle sequential=1 return="display_name" id=41194 api.Email.get={"return":"email"}
  # Gives me the contact just fine, but no email
  </code></pre>
  
  <p>Is there any way to coax drush cvapi into processing chained api calls? If it's not currently possible, is anybody working on it?</p>
  
  <p>In the meantime, how can I help to correct the API Explorer so it doesn't produce non-working drush commands?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-04-04T10:19:52.623Z
Comments.Text: Just to note that for the example you give, you can use ' return="display_name,email" ' without chaining, though that doesn't help the general case.
Comments.UserDisplayName: Aidan
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-04-05T07:57:42.023Z
Comments.Text: Thanks @Aidan -- that will give me the primary email, but with chaining in JS or PHP I can retrieve multiple emails associated with a contact.
Comments.UserDisplayName: Noah Miller
Tags: <api><documentation><drush><chaining>
Title: Can I chain API calls through drush?
ThreadText: # Can I chain API calls through drush?
  
  (Asked by: username_0 on 2016-04-04)
  
  API chaining works well in Javascript and PHP. For example, I can retrieve a contact's email addresses using this code generated by the API Explorer:
  Php
  $result = civicrm_api3('Contact', 'getsingle', array(
    'sequential' => 1,
    'return' => "display_name",
    'id' => 41194,
    'api.Email.get' => array('return' => "email"),
  ));
  
  Javascript  
  CRM.api3('Contact', 'getsingle', {
    "sequential": 1,
    "return": "display_name",
    "id": 41194,
    "api.Email.get": {"return":"email"}
  }).done(function(result) {
    // do something
  });
  
  However, the drush command generated by the API explorer doesn't work:
  drush cvapi Contact.getsingle sequential=1 return="display_name" id=41194 api.Email.get={"return":"email"}
  # Gives me the contact just fine, but no email
  
  Is there any way to coax drush cvapi into processing chained api calls? If it's not currently possible, is anybody working on it?
  In the meantime, how can I help to correct the API Explorer so it doesn't produce non-working drush commands?
  
  **Tags:** api, documentation, drush, chaining
  
  > **Comments:**
  > **username_1**: Just to note that for the example you give, you can use ' return="display_name,email" ' without chaining, though that doesn't help the general case.  
  > **username_0**: Thanks @username_1 -- that will give me the primary email, but with chaining in JS or PHP I can retrieve multiple emails associated with a contact.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2017-01-31. Score: 7 | Accepted answer
  
  Drush can read parameters from standard input in JSON format if you supply the argument --in=json. This is what we need for API chaining, because chaining uses nested parameters, and in contrast to a flat list of command line arguments (the default way to pass parameters to drush cvapi, JSON can handle nesting. So to retrieve the email addresses for contact ID 41194 along with that contact's display name, use:
  echo '{
    "sequential": 1,
    "return": "display_name",
    "id": 41194,
    "api.Email.get": {"return":"email"}
  }' | drush cvapi Contact.getsingle --in=json
  
  > **Comments:**
  > **username_2**: This is good, with a couple caveats: the output is hard to parse, and it doesn't work on Joomla/WordPress. To resolve those issues, change `drush cvapi` to [`cv api`]( https://github.com/civicrm/cv). That notation works on more CMS's and supports better output formats (JSON, PHP serialize(), and sometimes CSV).  
  
  ---
  
  