Answers.Body: <p>In Civi 4.6+, you can use pseudoconstants instead of IDs in many places - including for <code>option_group_id</code>.  Civi 4.7 expands the number of places you can use it.</p>
  
  <p>So you can get this down to 2 lines by replacing the first two with:</p>
  
  <pre><code>OPTION_VALUE_ID=`drush cvapi OptionValue.getvalue return=id option_group_id=from_email_address`.
  </code></pre>
  
  <p>Here's the trick: If the API Explorer allows you to select the value from a select list, that means that pseudoconstant substitution is available on that field.</p>
  
  <p>Unfortunately, I don't think you're going to get this down to one API call.  <code>create</code> requires an ID; you're just not going to get the ID without a <code>get</code> call.</p>
  
  <p>EDIT: It MAY be possible to get this down to one line!  See "options.match" and "options.match-mandatory" on <a href="https://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API" rel="nofollow noreferrer">this page</a>.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-10-03T17:20:09.433Z
Answers.LastActivityDate: 2017-01-24T14:08:45.900Z
Answers.LastEditDate: 2017-01-24T14:08:45.900Z
Answers.UserDisplayName: Jon G - Megaphone Tech
Answers.Body: <p>Looks like a case for API chaining. This or something like it <em>should</em> work:</p>
  
  <pre><code>drush cvapi OptionValue.getvalue return=id option_group_id=from_email_address \
      api.OptionValue.create={label:'"Fixed" &lt;info@fixed.org&gt;'}
  </code></pre>
  
  <p>Unfortunately, API chaining via drush <a href="https://civicrm.stackexchange.com/q/10887/446">does not appear to work</a>. Thanks to @noah-miller for pointing that out. I tried chaining via cli.php and that doesn't appear to work either. It seems not to register the <em>api.Entity.action</em> parameter at all (which makes me optimistic it is not a difficult fix).</p>
  
  <p>Jon's suggestion could be combined with what you already have to put it on one line, though the readability of this code is questionable:</p>
  
  <pre><code>drush cvapi OptionValue.create id=`drush cvapi OptionValue.getvalue \
      return=id option_group_id=from_email_address` label='"Fixed" &lt;info@fixed.org&gt;'
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-10-04T17:40:48.783Z
Answers.LastActivityDate: 2016-10-04T20:12:31.250Z
Answers.LastEditDate: 2017-04-13T12:53:13.017Z
Answers.UserDisplayName: universalhandle
Body: <p>I'm suprised that it is so hard to update an option value in a certain group using our API.</p>
  
  <p>I have been writing scripts as follows:</p>
  
  <ol>
  <li>get option group id where option group name = X (save as OptionGroupIDX)</li>
  <li>get option value id where option value name = Y and option group id = OptionGroupIDX =(save as OptionValueIDY)</li>
  <li>update OptionValueIDY title to Z</li>
  </ol>
  
  <p>I'd like to be able to write scripts that look more like:</p>
  
  <ol>
  <li>update the option value X in option group Y to value Z</li>
  </ol>
  
  <p>The real world shell script I'm using at the minute is as follows:</p>
  
  <pre><code>OPTION_GROUP_ID=`drush cvapi OptionGroup.getvalue return=id name=from_email_address`
  OPTION_VALUE_ID=`drush cvapi OptionValue.getvalue return=id option_group_id=$OPTION_GROUP_ID`
  drush cvapi OptionValue.create id=$OPTION_VALUE_ID label='"Fixed" &lt;info@fixed.org&gt;'
  </code></pre>
  
  <p>Anyone able to help me get it closer to a one liner? Would be awesome if so because patterns like this seem to come up a fair amount when I'm working with the API. Would chaining help here?</p>
  
Tags: <api><cli>
Title: Updating an option value with drush cvapi
ThreadText: # Updating an option value with drush cvapi
  
  (Asked by: username_0 on 2016-09-28)
  
  I'm suprised that it is so hard to update an option value in a certain group using our API.
  I have been writing scripts as follows:
  
  get option group id where option group name = X (save as OptionGroupIDX)
  get option value id where option value name = Y and option group id = OptionGroupIDX =(save as OptionValueIDY)
  update OptionValueIDY title to Z
  
  I'd like to be able to write scripts that look more like:
  
  update the option value X in option group Y to value Z
  
  The real world shell script I'm using at the minute is as follows:
  OPTION_GROUP_ID=`drush cvapi OptionGroup.getvalue return=id name=from_email_address`
  OPTION_VALUE_ID=`drush cvapi OptionValue.getvalue return=id option_group_id=$OPTION_GROUP_ID`
  drush cvapi OptionValue.create id=$OPTION_VALUE_ID label='"Fixed" '
  
  Anyone able to help me get it closer to a one liner? Would be awesome if so because patterns like this seem to come up a fair amount when I'm working with the API. Would chaining help here?
  
  **Tags:** api, cli
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2016-10-03. Score: 2 | Accepted answer
  
  In Civi 4.6+, you can use pseudoconstants instead of IDs in many places - including for option_group_id.  Civi 4.7 expands the number of places you can use it.
  So you can get this down to 2 lines by replacing the first two with:
  OPTION_VALUE_ID=`drush cvapi OptionValue.getvalue return=id option_group_id=from_email_address`.
  
  Here's the trick: If the API Explorer allows you to select the value from a select list, that means that pseudoconstant substitution is available on that field.
  Unfortunately, I don't think you're going to get this down to one API call.  create requires an ID; you're just not going to get the ID without a get call.
  EDIT: It MAY be possible to get this down to one line!  See "options.match" and "options.match-mandatory" on this page.
  
  
  ---
  
  ### Answer by username_2 on 2016-10-04. Score: 2
  
  Looks like a case for API chaining. This or something like it should work:
  drush cvapi OptionValue.getvalue return=id option_group_id=from_email_address \
      api.OptionValue.create={label:'"Fixed" '}
  
  Unfortunately, API chaining via drush does not appear to work. Thanks to @noah-miller for pointing that out. I tried chaining via cli.php and that doesn't appear to work either. It seems not to register the api.Entity.action parameter at all (which makes me optimistic it is not a difficult fix).
  Jon's suggestion could be combined with what you already have to put it on one line, though the readability of this code is questionable:
  drush cvapi OptionValue.create id=`drush cvapi OptionValue.getvalue \
      return=id option_group_id=from_email_address` label='"Fixed" '
  
  
  ---
  
  